我想重新命名在C#中的目录名称是一样只与不同的情况。
I am trying to rename a directory in c# to a name that is the same only with differing case.
例如: F:测试到f: TEST
For example: f:test to f:TEST
我已经试过这code:
I have tried this code:
var directory = new DirectoryInfo("f:test");
directory.MoveTo("f:TEST");
和我得到一个IOException异常 - 源和目标路径必须不同。我也曾尝试Directory.Move()具有相同的结果。
and I get a IOException - Source and destination path must be different. I have also tried Directory.Move() with the same result.
这是怎么做的?我一定要创建一个单独的临时目录,从原来的目录到临时目录将包含的文件,然后删除原始,和重命名的临时目录?
How is this done? Do I have to create a separate temp directory, move the contained files from the original directory to the temp directory, and then delete the original, and rename the temp directory?
推荐答案
那么,你并不需要创建一个单独的目录和移动的一切。只需重命名文件夹,以不同的东西,然后回到你想要的名称:
Well, you don't need to create a separate directory and move everything. Just rename the folder to something different and then back to the name you want:
var dir = new DirectoryInfo(@"F:test");
dir.MoveTo(@"F:test2");
dir.MoveTo(@"F:TEST");
相关推荐
最新文章