Home All Groups Group Topic Archive Search About

No of files in folder

Author
5 Jul 2006 2:07 PM
mabond
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

Author
5 Jul 2006 2:53 PM
zacks
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")
Author
5 Jul 2006 3:07 PM
mabond
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")
>
>
Author
5 Jul 2006 3:22 PM
mabond
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")
>
>
Author
5 Jul 2006 3:12 PM
mr_doles
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