Touch a large amount of files to update last write time

suggest change

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);

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents