除了:
System.IO.File.Move(sourceFileName, destFileName);
我有数以百万计的,使用上述将需要将近一周的时间来运行。
File.Move 是 Win32 API 的一个瘦包装器。我怀疑除了直接在磁盘上的块级别修改原始数据之外,还有什么更快的方法。我认为您不走运从托管代码中寻找更快的方法。
File.Move 反编译源码:
public static void Move(string sourceFileName, string destFileName)
{
if ((sourceFileName == null) || (destFileName == null))
{
throw new ArgumentNullException((sourceFileName == null) ? "sourceFileName" : "destFileName", Environment.GetResourceString("ArgumentNull_FileName"));
}
if ((sourceFileName.Length == 0) || (destFileName.Length == 0))
{
throw new ArgumentException(Environment.GetResourceString("Argument_EmptyFileName"), (sourceFileName.Length == 0) ? "sourceFileName" : "destFileName");
}
string fullPathInternal = Path.GetFullPathInternal(sourceFileName);
new FileIOPermission(FileIOPermissionAccess.Write | FileIOPermissionAccess.Read, new string[] { fullPathInternal }, false, false).Demand();
string dst = Path.GetFullPathInternal(destFileName);
new FileIOPermission(FileIOPermissionAccess.Write, new string[] { dst }, false, false).Demand();
if (!InternalExists(fullPathInternal))
{
__Error.WinIOError(2, fullPathInternal);
}
if (!Win32Native.MoveFile(fullPathInternal, dst))
{
__Error.WinIOError();
}
}