Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming files in folder c#

Tags:

c#

file

I have over 1000 files in a folder with names like abc_1, abc_2 ... abc_n

I want to delete this prefix 'abc_' from all the files. Any chance to not doing this manually because there are over 1000, and it will be a pain.

How can do this with c# ?

like image 304
Jason Paddle Avatar asked Sep 10 '12 08:09

Jason Paddle


People also ask

Can cp command rename file?

By Using cp CommandWe can use cp commands along with destination and source only. Here along with the file's path, the filename is also changed—the syntax for the cp command.


1 Answers

You can try with this code

DirectoryInfo d = new DirectoryInfo(@"C:\DirectoryToAccess"); FileInfo[] infos = d.GetFiles(); foreach(FileInfo f in infos) {     File.Move(f.FullName, f.FullName.Replace("abc_","")); } 
like image 125
Aghilas Yakoub Avatar answered Sep 28 '22 10:09

Aghilas Yakoub