enumerate files  
Author Message
wvantwiller





PostPosted: Tue Jan 18 00:38:22 CST 2005 Top

Dotnet >> enumerate files Hi,
I wanted to list all files in a directory so I found some code:
Dim t(), st As String

t = System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory,
"*.txt")

Dim en As System.Collections.IEnumerator

en = t.GetEnumerator

While en.MoveNext

st = CStr(en.Current)

ComBoFilel.Items.Add(st)

End While

To add just the name of the file rather than its whole path, do I need to do
some string manipulation to find the last "\" or is there a simpler method

Thanks

DV

DotNet265  
 
 
Mattias





PostPosted: Tue Jan 18 00:38:22 CST 2005 Top

Dotnet >> enumerate files
>To add just the name of the file rather than its whole path, do I need to do
>some string manipulation to find the last "\" or is there a simpler method

System.IO.Path.GetFileName()



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
 
Doug





PostPosted: Tue Jan 18 01:04:49 CST 2005 Top

Dotnet >> enumerate files I solved this using:

Dim st As String

Dim di As DirectoryInfo = New DirectoryInfo(Directory.GetCurrentDirectory)

st = di.FullName

Dim fis As FileInfo() = di.GetFiles("*.txt")

Dim fil As FileInfo

For Each fil In fis

st = fil.Name.ToString

ComBoPalleteLbl.Items.Add(st)

Next fil





"Doug Versch" <EMail@HideDomain.com> wrote in message
news:eeVtMZR$EMail@HideDomain.com...
> Hi,
> I wanted to list all files in a directory so I found some code:
> Dim t(), st As String
>
> t = System.IO.Directory.GetFiles(System.IO.Directory.GetCurrentDirectory,
> "*.txt")
>
> Dim en As System.Collections.IEnumerator
>
> en = t.GetEnumerator
>
> While en.MoveNext
>
> st = CStr(en.Current)
>
> ComBoFilel.Items.Add(st)
>
> End While
>
> To add just the name of the file rather than its whole path, do I need to
do
> some string manipulation to find the last "\" or is there a simpler method
>
> Thanks
>
> DV
>
>
>
>
>
>