No of files in folder

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I want to know how many files exist in a folder. I will use the number of
files to set the size of a string array which will contain the names of the
files. The array part I've done but need to know how to work out the number
of files in the folder. I'm currently using an arbitrary figure (40) but am
concerned that at some stage the number of files will exceed the size I've
set for the array

Thanks

Michael Bond
 
mabond said:
Hi

I want to know how many files exist in a folder. I will use the number of
files to set the size of a string array which will contain the names of the
files. The array part I've done but need to know how to work out the number
of files in the folder. I'm currently using an arbitrary figure (40) but am
concerned that at some stage the number of files will exceed the size I've
set for the array

Here's one way to do it.

Dim di as DirectoryInfo
Dim aFiles() as String

di = new DirectoryInfo("myDirectoryPath")
aFiles = di.GetFiles
MessageBox.Show("Contains " & cstr(aFiles.Count) & " files")
 
Hi

getting the following build error when I use this

"Value of type '1-dimensional array of System.IO.FileInfo' cannot be
converted to '1-dimensional array of String' because 'System.IO.FileInfo' is
not derived from 'String'."

Any ideas

Michael
 
Hi

I'm now going with

'Dim di As DirectoryInfo = New DirectoryInfo(pPath)
'Dim aFiles()
'aFiles = di.GetFiles

'Dim arraysize As Integer = aFiles.Length
'array = New String(arraysize, 1) {}

And it works. Thnaks for pointing me in the right direction.

Regards

Michael Bond
 
Back
Top