Here's RainingChain's script tweaked a little and converted to a full C# console app. Just compile and enjoy, tested in my own system.
Added functions:
Subdirectory scan and exception swallow when access is denied.
Operates only on timestamped files, this avoids affecting other data.
If timestamped file has another copy without the timestamp in the same folder, it deletes the timestamped one. This is for example when a program has been reinstalled and created the file again without the timestamp.
-
using System.Text.RegularExpressions;
using System;
using System.IO;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("FileHistory timestamp remover V1.0 - HamCode 2018");
Console.WriteLine("Based on a simple C# script by user RainingChain @ Superuser.com");
Console.WriteLine("--------------------------------------------------------------------");
Console.WriteLine();
ReRun:;
Console.WriteLine("Please enter files path, subdirectories will be scanned: ");
string input = Console.ReadLine();
try
{
foreach (string SubDir in Directory.GetDirectories(input))
{
try
{
string[] files = Directory.GetFiles(@SubDir, "*(????_??_?? ??_??_?? UTC).*", SearchOption.TopDirectoryOnly);
Console.WriteLine();
Console.Write("Current directory: ");
Console.Write(@SubDir);
Console.WriteLine(" The following files have been identified as containing a FileHistory timestamp:");
foreach (var value in files)
{
Console.Write(value);
}
Console.WriteLine();
Console.WriteLine();
for (int i = 0; i < files.Length; i++)
{
string newName = Regex.Replace(files[i], @" ?\(\d\d\d\d_\d\d_\d\d \d\d_\d\d_\d\d UTC\)", "");
//System.Diagnostics.Debug.WriteLine(files[i], newName);
File.SetAttributes(files[i], File.GetAttributes(files[i]) & ~FileAttributes.ReadOnly);
if (File.Exists(newName))
{
File.Delete(files[i]);
Console.Write("File deleted: ");
Console.Write(files[i]);
Console.WriteLine();
goto DoNothing;
}
System.IO.File.Move(files[i], newName);
Console.Write("Backup file renamed: ");
Console.Write(newName);
Console.WriteLine();
DoNothing:;
}
}
catch (Exception ds)
{
Console.WriteLine(ds);
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
goto ReRun;
}
Console.WriteLine("Completed, press any key to exit.");
Console.Read();
}
}
}
http://msdn.microsoft.com/en-us/library/ff794679(v=winembedded.60).aspx It's the fix for future, not the cure. – Davidenko – 2015-01-09T08:58:44.183
Possible duplicate of Batch File Rename(Timestamp removal) and Batch script to remove parts of a filename
– DavidPostill – 2015-01-09T10:08:02.197