重命名目录具有相同名称不同的情况下, [英] Renaming Directory with same name different case

查看:164
本文介绍了重命名目录具有相同名称不同的情况下,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重新命名在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");

这篇关于重命名目录具有相同名称不同的情况下,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆