Skip to content

Instantly share code, notes, and snippets.

@baobao
Created August 1, 2020 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baobao/8a12c1156263ff25232c0b3c4f3dd540 to your computer and use it in GitHub Desktop.
Save baobao/8a12c1156263ff25232c0b3c4f3dd540 to your computer and use it in GitHub Desktop.
Rename Sample `.txt` to `.cs`
#!/usr/bin/env dotnet-script
/**
* Rename Sample .txt to .cs
*/
if (Args == null || Args.Count < 0)
{
Console.WriteLine("Require arguments");
return;
}
var dirPath = Args[0];
var files = Directory.GetFiles(".", "*.txt");
foreach(var filePath in files)
{
var dirPath = Path.GetDirectoryName(filePath);
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath);
var newPath = $"{dirPath}/{fileNameWithoutExtension}.cs";
File.Move(filePath, newPath);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment