Created
September 30, 2019 22:01
-
-
Save greatb/65f39347ce29fc3117c25c565be148a8 to your computer and use it in GitHub Desktop.
Console app code to rename the file by its date stamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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