各位高手...小弟今天碰到一个头疼的问题..找了好多资料都没用
我在修改一个类别名的同时需要修改相对应的文件夹的名称...我用Directory.Move(OldUrl, NewUrl);[这个好像是移动文件夹的] 它提示错误:源路径必须和目标路径不同
请问我该怎么去重命名这文件夹呢
在此谢过了!
我在修改一个类别名的同时需要修改相对应的文件夹的名称...我用Directory.Move(OldUrl, NewUrl);[这个好像是移动文件夹的] 它提示错误:源路径必须和目标路径不同
请问我该怎么去重命名这文件夹呢
在此谢过了!
解决方案 »
- 执行insert into 插入语句,插入成功,但返回受影响的行数为-1???
- 这两个功能,dephi可以做,c#如何实现啊?
- 请问现在的一些通用软件都是用什么语言编写的?
- 急急急!
- 想做一个旗帜外观的一个可移动控件,程序运行后可拖动。没什么思路,各位大大们帮帮忙!
- 新手问题 请教各位老师!
- C#操作Excel的郁闷问题
- 要从htm文件提取字符串怎么做?
- 关于远程通信,请教大家一下
- c#怎么高效遍历文件
- 无法写入输出文件“H:\DDHCManagement\DDHCManagement\obj\Debug\DDHCManagement.pdb”: 系统错误 &H806d000c&
- c# winform 点击确定怎么跳转到下一个页面
Directory.Move(路径\old, 路径\new);
using System;
using System.IO;public class MoveToTest
{
public static void Main()
{ // Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo("TempDir"); // Create the directory only if it does not already exist.
if (di.Exists == false)
di.Create(); // Create a subdirectory in the directory just created.
DirectoryInfo dis = di.CreateSubdirectory("SubDir"); // Move the main directory. Note that the contents move with the directory.
if (Directory.Exists("NewTempDir") == false)
di.MoveTo("NewTempDir"); try
{
// Attempt to delete the subdirectory. Note that because it has been
// moved, an exception is thrown.
dis.Delete(true);
}
catch (Exception)
{
// Handle this exception in some way, such as with the following code:
// Console.WriteLine("That directory does not exist.");
} // Point the DirectoryInfo reference to the new directory.
//di = new DirectoryInfo("NewTempDir"); // Delete the directory.
//di.Delete(true);
}
}
string OldUrl=Server.MapPath("~/Upfile/"+ds.Tables[0].Rows[0]["ClassName"].ToString());
string NewUrl = Server.MapPath("~/Upfile/" + Text_ModifyClassName.Text.ToString().Trim());//修改资料下载目录
Directory.Move(OldUrl, NewUrl);我是这样写的...出错!
di.MoveTo(@"F:\kl2");
//執行後,F:\kl1變成了F:\kl2
Directory.Move(OldUrl, NewUrl);
中的OldUrl和 NewUrl是不是相同, Move方法要求这两个是不同的。
if (OldUrl!=NewUrl)
{
Directory.Move(OldUrl, NewUrl);
}
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());
}
}
}
你的問題不是Move管不管用的問題,而是你想要做什么?即然你要重命名,那就應該給他傳兩個不同的目錄進去。