Есть ли более эффективный способ переименования файла в Windows, кроме:
System.IO.File.Move(sourceFileName, destFileName);
У меня есть миллионы, и использование вышеуказанного займет почти неделю.
File.Move - это тонкая оболочка API Win32. Я сомневаюсь, что есть более быстрый способ, не связанный непосредственно с изменением необработанных данных на уровне блоков на диске. Я думаю, вам не повезло, что вы искали более быстрый путь от управляемого кода.
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();
}
}