-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
45 lines (40 loc) · 1.35 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.IO;
namespace rename_files
{
class Program
{
static void Main(string[] args)
{
if(args.Length!= 4) {
Console.WriteLine("Invalid Arguments");
Console.WriteLine("Usage: rename-files <folder> <target> <desination> <pattern>");
Console.WriteLine("i.e. rename-files /files javascript typescript *.png");
return;
}
var folder = args[0]; // folder
var target = args[1]; //
var destination = args[2];
var pattern = args[3];
var files = Directory.GetFiles(folder, pattern, SearchOption.AllDirectories);
foreach(var file in files)
{
if(file.Contains(target))
{
var output = file.Replace(target, destination);
Console.WriteLine(string.Format("{0} -> {1}", file, output));
try
{
File.Copy(file, output);
}
catch
{
Console.WriteLine("{0} skipped", file);
}
}
}
Console.WriteLine("Please any key to exit.");
Console.ReadLine();
}
}
}