List PDFiles = Directory.GetFiles("C:\folder1\", "*.pdf", SearchOption.AllDirectories).Where(x => File.GetLastAccessTime(x).Date.ToShortDateString() == DateTime.Today.Date.ToShortDateString())
.Select(x => x)
.ToList();
Now how can I add the next files, from C:\folder2 path? (with the same extension and comparation )?
I tried something like this, but I don't know if is such a good idea:
foreach (var test in Directory.GetFiles("C:\folder2\, "*.pdf", SearchOption.AllDirectories).Where(x => File.GetLastAccessTime(x).Date.ToShortDateString() == DateTime.Today.Date.ToShortDateString()))
{
PDFiles.Add(test);
}
VulpesPosted Jun 27, 2013, 5:40 PM
List
.Union(Directory.GetFiles(@"C:\folder1\", "*.pdf", SearchOption.AllDirectories))
.Where(x => File.GetLastAccessTime(x).Date.ToShortDateString() == DateTime.Today.Date.ToShortDateString())
.Select(x => x)
.ToList();
As it's certain that there won't be any duplicate file paths, you could also use Concat instead of Union - in fact, the former might be faster on folders which contain a lot of files.
VulpesPosted Jun 28, 2013, 5:26 AM
DanPosted Jun 28, 2013, 5:21 AM
VulpesPosted Jun 28, 2013, 5:18 AM
DanPosted Jun 28, 2013, 5:13 AM
VulpesPosted Jun 28, 2013, 5:10 AM
Are you saying that you want to amalgamate the files in the two folders but eliminate any duplicate files?
DanPosted Jun 28, 2013, 5:05 AM
EDIT: He duplicates the file because the folder path is not the same ( folder1 <> folder2 )