把c:\aa.txt
改名成   c:\bb.txt

string   srcFileName=@ "c:\meng\a.txt ";
string   destFileName=@ "c:\meng\b.txt ";

string   srcFolderPath=@ "c:\temp ";
string   destFolderPath=@ "c:\temp11 ";
//方法一  
if   (System.IO.File.Exists(srcFileName))  
{  
System.IO.File.Move(srcFileName,destFileName);
}  
if   (System.IO.Directory.Exists(srcFolderPath))  
{  
System.IO.Directory.Move(srcFolderPath,destFolderPath);
}

//方法二
if   (System.IO.File.Exists(srcFileName))  
{  
System.IO.FileInfo   file=new   System.IO.FileInfo(srcFileName);  
file.MoveTo(destFileName);  
}  
if   (System.IO.Directory.Exists(srcFolderPath))  
{  
System.IO.DirectoryInfo   folder=new   System.IO.DirectoryInfo(srcFolderPath);  
folder.MoveTo(destFolderPath);  
}

posted on 2011-08-14 12:11  易尔购  阅读(3874)  评论(0编辑  收藏  举报