Skip to content

Instantly share code, notes, and snippets.

@pisarukv
Last active August 29, 2015 14:14
Show Gist options
  • Save pisarukv/96a7dbd22a81e905a573 to your computer and use it in GitHub Desktop.
Save pisarukv/96a7dbd22a81e905a573 to your computer and use it in GitHub Desktop.
c#
using System;
using System.IO;
namespace Rename
{
class MainClass
{
static DirectoryInfo d = new DirectoryInfo(Directory.GetCurrentDirectory());
static FileInfo[] Files = d.GetFiles("*.png");
public static void Main(string[] args)
{
Console.WriteLine(Directory.GetCurrentDirectory());
foreach (var a in Files)
{
Console.WriteLine(a.Name);
if (a.Name.Contains("@"))
{
var index = a.FullName.LastIndexOf('.');
var path = a.FullName.Substring(0, index - 3).TrimEnd() + ".png";
try
{
File.Move(a.FullName, path);
}
catch
{
File.Delete(path);
File.Move(a.FullName, path);
}
}
}
if(args.Length != 0)
{
Files = d.GetFiles("*.png");
foreach(var a in Files)
{
File.Move(a.FullName, args[0]+a.FullName);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment