files in folders

T

tim

Hi all!
How to create array of string, which contains names of all files with full
path in special folder (e.g. c:\windows). In this folder it may be
subfolders of various levels.
 
S

Shiva

Did you try Directory.GetFiles()?

For e.g. Directory.GetFiles (@"C:\Windows") gets you the list of files with
full path as a string array.

HTH

Hi all!
How to create array of string, which contains names of all files with full
path in special folder (e.g. c:\windows). In this folder it may be
subfolders of various levels.
 
T

tim

oh, I'm find in MSDN, thanks for suggestion:

' Process all files in the directory passed in, recurse on any directories
' that are found, and process the files they contain.

Public Shared Sub ProcessDirectory(ByVal targetDirectory As String)
Dim fileEntries As String() = Directory.GetFiles(targetDirectory)
' Process the list of files found in the directory.
Dim fileName As String
For Each fileName In fileEntries
ProcessFile(fileName)

Next fileName
Dim subdirectoryEntries As String() =
Directory.GetDirectories(targetDirectory)
' Recurse into subdirectories of this directory.
Dim subdirectory As String
For Each subdirectory In subdirectoryEntries
ProcessDirectory(subdirectory)
Next subdirectory

End Sub 'ProcessDirectory

' Insert logic for processing found files here.
Public Shared Sub ProcessFile(ByVal path As String)
Console.WriteLine("Processed file '{0}'.", path)
End Sub 'ProcessFile
End Class 'RecursiveFileProcessor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top