public Rename(string sourceFile, string destinyFile)
if(System.IO.File.Exist(sourceFile))
{
try
{
System.IO.File.Move(sourceFile, destinyFile);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
或者先File.Copy(sourceFile, destinyFile);
再File.Delete(sourceFile);
参考ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfsystemiofileclasstopic.htm
if(System.IO.File.Exist(sourceFile))
{
try
{
System.IO.File.Move(sourceFile, destinyFile);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
或者先File.Copy(sourceFile, destinyFile);
再File.Delete(sourceFile);
参考ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfsystemiofileclasstopic.htm
public Rename(string sourceFile, string destinyFile)
{
if(System.IO.File.Exist(sourceFile))
{
try
{
System.IO.File.Move(sourceFile, destinyFile);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
else
{
Console.WriteLine("源文件{0}不存在!", sourceFile);
}
}
proc.StartInfo.FileName="ren";
proc.StartInfo.CreateNoWindow=true;
proc.StartInfo.Arguments="xxx.doc yyy.txt";
proc.Start();
{
string path = @"D:\test";
string[] spacifyFile=Directory.GetFiles(path);
int i=0;
foreach(string tempFile in spacifyFile)
{
i++;
System.Diagnostics.ProcessStartInfo Info = new System.Diagnostics.ProcessStartInfo();
Info.WindowStyle=System.Diagnostics.ProcessWindowStyle.Hidden;
Info.FileName = "cmd.exe";
string renameStr = @"/c rename "+tempFile+" "+i.ToString()+"eeee.txt";
Info.Arguments =renameStr;
//Info.RedirectStandardOutput = true;
//Info.UseShellExecute = false;
System.Diagnostics.Process.Start(Info);
}
}
记得加名字空间:using System.Diagnostics;
同一逻辑盘:改的是FAT 表文件名和偏移位置
源和目标不在同一盘:重写所有内容(理论上来说比复制还慢)