Getting all files in Dir and Subdirs

  • Thread starter Thread starter augustesen
  • Start date Start date
A

augustesen

Hi

I am looking for a way to get all the files in a specific folder and
its subfolders (and the subfolders subfolders and so on).

Is there an easy way of doing this? Or do I have to go through every
single folder and subfolder?

Regards
Søren Augustesen
 
Hi Arun

I have looked into IO class, and I have tried using them.

I have tried the Directory.GetFileSystemEntries(dir) but that only
returns the dirs/files of the first sub layer. The problem is that I
don't know how many sublayers a folder has, so I can't just enumerate
through X numbers of directories and sub dirs to get the files.

What I am looking for is a command/rutine that will return all
filenames from all the sublayers in a folder.

Anyone know anything like this??

Regards
Søren Augustesen
 
Hi

This code gives you all the files and subdirs in a given folder

public void ProcessDirectory(string targetDirectory)
{
// Handels the files found in the main folder
string [] fileEntries = Directory.GetFiles(targetDirectory);
foreach(string fileName in fileEntries)
{
ProcessFile(fileName); //This function does what ever you want
to do with the files
}

// Finding the sub directories in the folder
string [] subdirectoryEntries =
Directory.GetDirectories(targetDirectory);

// For each subfolder this function is called again
foreach(string subdirectory in subdirectoryEntries)
{
AllDirNames.Add(subdirectory); //Add the Dir location to a
Global ArrayList
ProcessDirectory(subdirectory); //Calls this function againg
with the subdir as parmeter
}
}

Regards
Søren Augustesen


(e-mail address removed) skrev:
 
Back
Top