Posts o[c#] get files by multiple extensions or but LastWriteTime
Post
Cancel

o[c#] get files by multiple extensions or but LastWriteTime

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
///////////get by modified day, get today files.

           var directory = new DirectoryInfo(dest_dir);
           List<FileInfo> files = directory.GetFiles()
                                    .Where(file => file.LastWriteTime > DateTime.Today).ToList();

///////////get by mutliple filename wildcards.

//single mask - files = General.GetFiles(dest_dir, "*" + DateTime.Today.AddDays(-1).ToString("yyyyMMdd") + "*.dat", SearchOption.TopDirectoryOnly);
//multiple - files = GetFiles(des_dir, "*" + DateTime.Today.AddDays(-1).ToString("yyyyMMdd") + "*.dat|" + "*" + DateTime.Today.AddDays(-2).ToString("yyyyMMdd") + "*.dat|" + "*" + DateTime.Today.AddDays(-3).ToString("yyyyMMdd") + "*.dat", SearchOption.TopDirectoryOnly);

internal static string[] GetFiles(string sourceFolder, string filters, System.IO.SearchOption searchOption)
{
    return filters.Split('|').SelectMany(filter => System.IO.Directory.GetFiles(sourceFolder, filter, searchOption)).ToArray();
}

origin - http://www.pipiscrew.com/?p=6294 c-get-files-by-multiple-extensions-or-but-lastwritetime

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags