c#怎样重命名文件夹

c#怎样重命名文件夹... c#怎样重命名文件夹 展开
 我来答
xyz5819
高粉答主

2011-04-21 · 醉心答题,欢迎关注
知道顶级答主
回答量:7.8万
采纳率:63%
帮助的人:3.3亿
展开全部
c#如何给文件或文件夹重命名

用file.move

原形:
public static void Move (
string sourceFileName,
string destFileName
)
参数
sourceFileName
要移动的文件的名称。
destFileName
文件的新路径。

using System;
using System.IO;

class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
string path2 = @"c:\temp2\MyTest.txt";
try
{
if (!File.Exists(path))
{
// This statement ensures that the file is created,
// but the handle is not kept.
using (FileStream fs = File.Create(path)) {}
}

// Ensure that the target does not exist.
if (File.Exists(path2))
File.Delete(path2);

// Move the file.
File.Move(path, path2);
Console.WriteLine("{0} was moved to {1}.", path, path2);

// See if the original exists now.
if (File.Exists(path))
{
Console.WriteLine("The original file still exists, which is unexpected.");
}
else
{
Console.WriteLine("The original file no longer exists, which is expected.");
}

}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
干吗寻找周杰伦
2011-04-21 · TA获得超过1805个赞
知道小有建树答主
回答量:1949
采纳率:0%
帮助的人:718万
展开全部
看一下c#的api
或者用对象
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
egghead008
2011-04-21 · TA获得超过1164个赞
知道小有建树答主
回答量:1424
采纳率:100%
帮助的人:1418万
展开全部
没有那么复杂的啦,直接这样就可以啦:
Directory.Move(@"d:\textddd", @"d:\textAAA");
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式