PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET No of files in folder

Reply

No of files in folder

 
Thread Tools Rate Thread
Old 05-07-2006, 03:07 PM   #1
=?Utf-8?B?bWFib25k?=
Guest
 
Posts: n/a
Default No of files in folder


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
  Reply With Quote
Old 05-07-2006, 03:53 PM   #2
zacks@construction-imaging.com
Guest
 
Posts: n/a
Default Re: No of files in folder


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")

  Reply With Quote
Old 05-07-2006, 04:07 PM   #3
=?Utf-8?B?bWFib25k?=
Guest
 
Posts: n/a
Default Re: No of files in folder

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")
>
>

  Reply With Quote
Old 05-07-2006, 04:12 PM   #4
mr_doles
Guest
 
Posts: n/a
Default Re: No of files in folder

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

  Reply With Quote
Old 05-07-2006, 04:22 PM   #5
=?Utf-8?B?bWFib25k?=
Guest
 
Posts: n/a
Default Re: No of files in folder

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")
>
>

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off