Group,

I'm counting the number of files in a folder using the following code:

Dim counter = My.Computer.FileSystem.GetFiles(folderName)

This produces a value that doesn't appear to be either a string or an integer. Would you know how to convert this value into an integer that can be used?

Don

Recommended Answers

All 2 Replies

GetFiles returns an array. Something like this should work:

Dim counter = My.Computer.FileSystem.GetFiles(folderName).Length

One thing to keep in mind. If you plan on using the array of filenames later,generally, one would create an array to hold the names and use the length property from it:

Dim filenames = My.Computer.FileSystem.GetFiles(folderName)
Dim counter = filenames.Length

Another thing to keep in mind. FileSystem is VB specific. Many programmers tend to switch to the System.IO library, which is a CLR library and can be used in any of the .net languages.

tinstaafl, thanks for the code and the tips. Most importantly, it worked perfectly!

Thanks for the help!

Don

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.