Beispiel #1
0
 public static void ParallelTruncateFiles(TruncateOptions opt, List <string> files)
 {
     Parallel.ForEach(files, (file) =>
     {
         string fullPath = Path.GetFullPath(file);
         TruncateFile(opt, fullPath);
     });
 }
Beispiel #2
0
 public static void TruncateFiles(TruncateOptions opt, List <string> files)
 {
     foreach (string f in files)
     {
         string fullPath = Path.GetFullPath(f);
         TruncateFile(opt, fullPath);
     }
 }
Beispiel #3
0
 private static void TruncateFile(TruncateOptions opt, string fileFullPath)
 {
     if (opt == null)
     {
         throw new ArgumentNullException(nameof(opt));
     }
     try
     {
         using (FileStream fs = new FileStream(fileFullPath, opt.FileMode))
         {
             fs.SetLength(opt.Size);
             // Make sure that the changes take effect when the stream is
             // flushed to disk.
             fs.Seek(fs.Length, SeekOrigin.Begin);
         }
     }
     catch (FileNotFoundException)
     {
         if (!opt.Quiet)
         {
             Console.WriteLine($"File not found: {fileFullPath}");
         }
     }
 }