This example updates last write time of a huge number of files (using System.IO.Directory.EnumerateFiles
instead of System.IO.Directory.GetFiles()
). Optionally you can specify a search pattern (default is "*.*"
and eventually search through a directory tree (not only the specified directory):
public static void Touch(string path,
string searchPattern = "*.*",
SearchOptions options = SearchOptions.None)
{
var now = DateTime.Now;
foreach (var filePath in Directory.EnumerateFiles(path, searchPattern, options))
{
File.SetLastWriteTime(filePath, now);
}
}