开发者

Rename folders in c# Form

i try to make a Form program in c# to rename a lot of fol开发者_JS百科ders. The Customers has to choose the folder (and the name to rename), where all the folders are include, for example in c:\folders\ are this folders:

1991 - title1
1992 - title2
1993 - title3
1994 - title4

And now i will change the year into a name, like this:

name - title1
name - title2
name - title3
name - title4

Example pic:

Rename folders in c# Form

I hope you unterstand what i want :-) and you can help me with this.

Regards, matthias


A few hints:

  1. Get all files (recursively if you want) with

    Directory.GetFiles(@"c:\folder\")

  2. Rename all files with

    File.Move(@"C:\folder\oldname", @"C:\folder\newname");

If your file format is like that you can simply split the filename at "-" & replace the first part with your name.


You can use the FolderBrowserDialog class to select the directory, the Directory class to rename it and String.Split or a RegEx to modify the name.

Store the selected directories and their names to a collection of your choice.


The Directory Class will do this.

http://msdn.microsoft.com/en-us/library/system.io.directory.aspx

You should also take a look at Path to help figure out what to replace.

http://msdn.microsoft.com/en-us/library/system.io.path_members(v=VS.71).aspx

// Move the directory.
Directory.Move(path, target);


Use others answers and for renaming i would do a RegEx replace like this.

string new_folder_name = Regex.Replace(/*old folder name*/, @"\d\d\d\d", /*user provided name*/)


In the command prompt the following

for /L %n in (1991,1,2010) do ren "(%n) - *" "name - *"

should do what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜