Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Wednesday, February 16, 2011

Recursive method for Find all directory and inside the directory found all files

// Insert logic for processing found files here.
public static void ProcessFile(string path)
{
//Logic here in file
}

// Process all files in the directory passed in, recurse on any directories
// that are found, and process the files they contain.
public static void ProcessDirectory(string targetDirectory)
{
// Process the list of files found in the directory.
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries){
ProcessFile(fileName);
}


// Recurse into subdirectories of this directory.
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries)
{
ProcessDirectory(subdirectory);

}
}

//call the Method

string FilePath = Request.PhysicalApplicationPath + "UploadFile";
if (Directory.Exists(FilePath))
{
ProcessDirectory(FilePath);

}

No comments:

Post a Comment