PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
No of files in folder
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
No of files in folder
![]() |
No of files in folder |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
mabond wrote: > 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") |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 "zacks@construction-imaging.com" wrote: > > mabond wrote: > > 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") > > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Dim counter As _
System.Collections.ObjectModel.ReadOnlyCollection(Of String) counter = My.Computer.FileSystem.GetFiles("C:\TestDir") MsgBox("number of files is " & CStr(counter.Count)) Taken from: http://msdn2.microsoft.com/en-us/library/wt8k42e9.aspx |
|
|
|
#5 |
|
Guest
Posts: n/a
|
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 "zacks@construction-imaging.com" wrote: > > mabond wrote: > > 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") > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

