C #, when renaming a file, noRenameThis function uses the fileinfo. moveTo method, and transfers moveTo to a new name in the original directory, that is, rename.
This method is used to rename the names of all subfolders in the folder. The names of the new subfolders can use format strings, such as dir {0: 0000}. The renamed subfolders are as follows: dir0001, dir0002, and dir0003.
For more information, see the example.Code.
-
-
- /// <Summary>
-
- ///Rename all subfolders in the folder
-
- /// </Summary>
- /// <Param name = "directoryname">Folder name</Param>
-
- /// <Param name = "newdirectoryname">New subfolder name Format String</Param>
-
- Public VoidRenamedirectories (StringDirectoryname,StringNewdirectoryname)
-
- {
-
- IntI = 1;
- String[] Sdirectories = directory. getdirectories (directoryname );
-
- Foreach(StringSdirectoryInSdirectories)
-
- {
-
- StringSdirectoryname = path. getfilename (sdirectory );
- StringSnewdirectoryname =String. Format (newdirectoryname, I ++ );
-
- StringSnewdirectory = path. Combine (directoryname, snewdirectoryname );
-
- Directory. Move (sdirectory, snewdirectory );
-
- }
-
- }
// Full path name of the original file in the list
String oldstr = ft. fileroute + @ "/" + ft. filename + ft. exname;
// New file name
String newstr = ft. fileroute + @ "/" + prechar + name + nextchar + ft. exname;
// Rename Method
Fileinfo Fi = new fileinfo (oldstr );
Fi. moveTo (path. Combine (newstr ));
Both of them are supported.