|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
No of files in folderHi
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 wrote:
> Hi Here's one way to do it.> > 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 > 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 Show quoteHide quote "za***@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") > > 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 Show quoteHide quote "za***@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") > > 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
CopyFile() and Progress Bar?
Get object from name how to parse an Enum Structure in vb.net Removing the " Web Form Designer Generated Code " region after converting from ASP.NET 1.1 to ASP.NE Getting form to run its load event without showing form activate a click onto a picture button Who is using a given port? Weird problem Convert Color image to Gray Shade Image Which would be better MS ACESS or SQL Server for VB Desktop application |
|||||||||||||||||||||||