C#以编程方式重命名文件夹 [英] C# Rename Folder Programatically
本文介绍了C#以编程方式重命名文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想在UNC路径中重命名文件夹和子文件夹。
我尝试了很多但是,我找不到解决方案,
注意:我不喜欢不想创建文件夹/移动现有文件夹使用
System.IO.Directory.Move
现有文件夹需要更改文件夹名称。
任何帮助将不胜感激
谢谢和问候
Vishwa
Hi guys,
I want to rename folders and sub folder in UNC path.
I tried a lot but,I am not able find the solution,
Note: I don't want Create folders/Move the existing folder using
System.IO.Directory.Move
Existing folder need to change the folder name.
Any help will be appreciated
Thanks and regards
Vishwa
推荐答案
如果您有访问权限,请记住您只能重命名该文件夹。
movie是该文件夹的名称并存在于D驱动器,并重命名为电影或任何你想要的东西。
尝试以下代码
Remember you can only rename the folder, if you have the access rights.
"movie" is the name of the folder and exist in D drive and is renamed to movies or anything you desire.
try the below code
System.IO.Directory.Move(@"D:\movie", @"D:\movies");
使用 Directory.Move [ ^ ] method。
Use the Directory.Move[^] method.
< a href =http://www.c-sharpcorner.com/resources/740/how-to-rename-a-directory-or-folder-in-c-sharp.aspx>如何重命名目录或文件夹在C# [ ^ ]
或者看看这个例子 -
How to rename a directory or folder in C#[^]
OR see this example-
using System;
using System.IO;
namespace Folder
{
class Program
{
static void Main(string[] args)
{
string sourceDirectory = @"C:\sourcelocation";
string destinationDirectory = @"C:\destinationlocation";
try
{
Directory.Move(sourceDirectory, destinationDirectory);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
这篇关于C#以编程方式重命名文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文