hi , i just find this code in a website. One thing i need your help. how to create a datatable with all the file information inside the foreach and display the information in the Gridview. Hope you understood what iam trying to say. search directories for doc files and display those file informatin in the Gridview
namespace Recursion
{
class IterateFolders
{
public static void Main(string[] args)
{
//Create a Directory object using DirectoryInfo
DirectoryInfo dir =
new DirectoryInfo(@"C:\Program
Files\Adobe\Acrobat 5.0");
//Pass the Directory for displaying the contents
getDirsFiles(dir);
}
//this is the recursive function
public static void getDirsFiles(DirectoryInfo
d)
{
//create an array of files using FileInfo object
FileInfo [] files;
//get all files for the current directory
files = d.GetFiles("*.*");
//iterate through the directory and print the files
foreach (FileInfo file in files)
{
//get details of each file using file object
String fileName = file.FullName;
String fileSize = file.Length.ToString();
String fileExtension =file.Extension;
String fileCreated = file.LastWriteTime.ToStrin
g();
io.WriteLine(fileName + " " + fileSize +
" " + fileExtension + " " + fileCreated);
}
//get sub-folders for the current directory
DirectoryInfo [] dirs = d.GetDirectories("*.*");
//This is the code that calls
//the getDirsFiles (calls itself recursively)
//This is also the stopping point
//(End Condition) for this recursion function
//as it loops through until
//reaches the child folder and then stops.
foreach (DirectoryInfo dir in dirs)
{
io.WriteLine("--------->> {0} ", dir.Name);
getDirsFiles(dir);
}
}
}
}
Start Free Trial