我有改变一些文件的名称(即,动态添加ID到每一个名字),使用C#中的文件夹中。一个任务
I have a task of changing the names of some files (that is, adding id to each name dynamically) in a folder using C#.
例:要的help.txt 1help.txt
Example: help.txt to 1help.txt
我怎样才能做到这一点?
How can I do this?
看一看的 FileInfo的。
做这样的事情:
void RenameThem()
{
DirectoryInfo d = new DirectoryInfo("c:/dir/");
FileInfo[] infos = d.GetFiles("*.myfiles");
foreach(FileInfo f in infos)
{
// Do the renaming here
File.Move(f.FullName, Path.Combine(f.DirectoryName, "1" + f.Name));
}
}