Skip to content

Instantly share code, notes, and snippets.

@greatb
Created September 30, 2019 22:01
Show Gist options
  • Save greatb/65f39347ce29fc3117c25c565be148a8 to your computer and use it in GitHub Desktop.
Save greatb/65f39347ce29fc3117c25c565be148a8 to your computer and use it in GitHub Desktop.
Console app code to rename the file by its date stamp
using System;
using System.IO;
// dotnet .\FileConsole.dll C:\Photos\Trip\2020-08-Europe Mdd
namespace FileConsole
{
class Program
{
static void Main(string[] args)
{
string[] fileNames = Directory.GetFiles(args[0]);
string toFlde = args[0] + @"\with-time-name\";
if (!Directory.Exists(toFlde))
{
Directory.CreateDirectory(toFlde);
string newFileName;
for (int i = 0; i < fileNames.Length; i++)
{
FileInfo file = new FileInfo(fileNames[i]);
newFileName = toFlde + file.CreationTime.ToString(args[1] + "-HHmmss") + "-" + file.Name;
File.Copy(file.FullName, newFileName);
Console.WriteLine(newFileName);
}
}
else
{
Console.WriteLine($"Folder {toFlde} exists");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment