Created
May 6, 2014 07:13
-
-
Save abhi1010/a1bcc60b383a0bc72d5f to your computer and use it in GitHub Desktop.
Recursively Read Directories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static void Directories(string strFolderPath, string fType) | |
{ | |
DirectoryInfo info = new DirectoryInfo(strFolderPath); | |
ArrayList fileList = new ArrayList(); | |
SubDirectories(fType, ref fileList, info.FullName, ""); | |
return fileList; | |
} | |
private static void SubDirectories(string fType, ref ArrayList fileList, string location, string tab) | |
{ | |
DirectoryInfo subDir = new DirectoryInfo(location); | |
DirectoryInfo[] dirs = subDir.GetDirectories(); | |
if (dirs.Length == 0) | |
{ | |
//Console.WriteLine(tab + " @@@@@@@ " + location); | |
ShowFiles(fType, ref fileList, location); | |
return; | |
} | |
else | |
{ | |
//Console.WriteLine(tab + " #### " + location); | |
ShowFiles(fType, ref fileList, location); | |
foreach (DirectoryInfo subSingleDir in dirs) | |
{ | |
SubDirectories(fType, ref fileList, subSingleDir.FullName, tab + "\t"); | |
} | |
} | |
} | |
private static void ShowFiles(string fType, ref ArrayList fileList, string location) | |
{ | |
DirectoryInfo dirFiles = new DirectoryInfo(location); | |
FileInfo[] files ; | |
if(fType!=null && fType.Length > 0) | |
files = dirFiles.GetFiles(fType); | |
else files = dirFiles.GetFiles(); | |
foreach (FileInfo file in files) | |
{ | |
Console.WriteLine(file.FullName); | |
fileList.Add(file.FullName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment