Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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