5
Answers

Sort specific files from multiple directories

Photo of kritika Rana

kritika Rana

11y
923
1
Hi

I have large number of files in multiple directories Like there is a root dir Test and sub dir as test1, test2 and so on
All the sub dir have file named as "A" I want to sort all the files from all the sub dir and put them together and then send as email

Regards
Kritika

Answers (5)

0
Photo of Iftikar Hussain
NA 18.9k 275.5k 11y
Hi,
        You can all files of sub folder like this

string path = @"C:\Test";
DirectoryInfo dinfo = new DirectoryInfo(path);
var files = dinfo.EnumerateFiles("*", SearchOption.AllDirectories);
//var files = dinfo.GetFiles("*");
List<FileData> fileDatas = new List<FileData>();
foreach (var fileInfo in files)
{
                var filePath = fileInfo.FullName;
                //DateTime dt;
                //using (var textFile = File.OpenText(filePath))
                //{
                //    dt = GetDateValue(textFile.ReadLine(), fileInfo.Name);
                //}
                //var fileData = new FileData { FileName = fileInfo.Name, FilePath = filePath, FileModifiedDate = dt };
                //fileDatas.Add(fileData);
}

Regards,
Iftikar
Accepted
0
Photo of Iftikar Hussain
NA 18.9k 275.5k 11y
I put those, so that you may incorporate this for your earlier requirement. Otherwise you can remove it. I believe you want the same as you asked on Friday.

Regards,
Iftikar
0
Photo of kritika Rana
NA 252 75.7k 11y
Hi

Why you put some lines as comment . Are they not required??

Kritika
0
Photo of kritika Rana
NA 252 75.7k 11y
Yes they have different extention but with same name.
0
Photo of Joxin Stanly
NA 386 34.8k 11y
hi,

need more clarity in your question..

you have mentioned that multiple sub folders contains file with same name..

but i don't think you can copy all of them together into a single folder because only a unique file name(with same extension) can exist in a folder.. either it will be overwritten or it will throw error..