Friday, August 22, 2008

get all sub directories and files from those directories

private void getFilesInSubs()
{
MyOrionDS.FileInfo.Clear()
;
string path = textBox1.Text;

DirectoryInfo subdirs = new DirectoryInfo(path);
DirectoryInfo[] dirs = subdirs.GetDirectories("*");
foreach (DirectoryInfo directory in dirs)
{
System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(directory.FullName);
if (tbxFileType.Text.Length == 0)
{
pattern = "*.*";
}
else
{
pattern = "*." + tbxFileType.Text;
}
System.IO.FileInfo[] fInfo = dInfo.GetFiles(pattern);
foreach (System.IO.FileInfo fi in fInfo)
{
//string fileInfoStuff = "";
string fileName = fi.FullName;
//string fileversion = "";
DateTime creationTime = fi.CreationTime;
DateTime LastModifyDate = fi.LastWriteTime;
System.Diagnostics.FileVersionInfo myFileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(fileName);
//MessageBox.Show(myFileVersionInfo.ToString());
//fileInfoStuff = fi.Name + " | " + creationTime + " | " + myFileVersionInfo.FileVersion;

OrionDataSet.FileInfoRow newFileInfoRow = (OrionDataSet.FileInfoRow)MyOrionDS.FileInfo.NewFileInfoRow();

newFileInfoRow.FileName = fi.FullName;
newFileInfoRow.LastModifyDate = LastModifyDate;
newFileInfoRow.CreateDate = creationTime;
newFileInfoRow.VersionNumber = myFileVersionInfo.FileVersion;

MyOrionDS.FileInfo.Rows.Add(newFileInfoRow);
MyOrionDS.FileInfo.AcceptChanges();



//lbxPreview.Items.Add(fileInfoStuff);
}
}

dataGridView1.DataSource = MyOrionDS.FileInfo;
}

No comments: