Get All Files Under A Directory(Recursive)
// deep traversal
Public void GetAllFiles(string directorypath)
{
// get sub dirs
string[] Dirs = System.IO.Directory.GetDirectories(directorypath);
if (Dirs.Count>0)
{// have subdirectory
foreach (string dir in Dirs)
{
GetAllFiles(dir); // recursive calling
}}
// handle file in folder
// get all files
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(directorypath);
foreach (System.IO.FileInfo fi in di)
{
// handle each file
}
}
0 Comments:
Post a Comment
<< Home