Performance issue when moving of files on network shares
I'm writing an application which can copy files on a network share. Usually the files are moved on the same physical hard drive. If you test this with Windows Explorer, this operation will be executed really quickly. It seems, that Windows knows about the same location and does a real movement and not a copy and delete (which would be slower).
Let's say you want to copy a set of files:
\\computer\share\fileA.txt
\\computer\share\fileB.txt
The Destination is for example:
\\computer\share\subfolder
The application uses the Windows Shell API (I wrote the application in Delphi, but the problem should be the same for other languages as well):
with SHFileOpStruct do
begin
Wnd := 0;
wFunc := FO_MOVE;
pFrom := PChar ('\\computer\share\fileA.txt'+#0
+'\\computer\share\fileB.txt'+ #0#0);
pTo := PCahr ('\\computer\share\subfolder' + #0#0);
fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
end;
Result := SHFileOperationW (SHFileOpStruct);
Unfortunately this code does a "copy and delete" which is much slower on large files or if you have lots of files. How can 开发者_JAVA技巧I avoid this? Is there any way to tell the move operation, that the folders are on the same hard drive? Perhaps there is some other notation for the network path.
Or is there a different API function which is uses by Windows Explorer?
For a short comparison:
- number of files : 260
- file size for each of the files : 11 kB
- time for move in Explorer : 2 sec
- time for move with SHFILEOPERATION : 20 sec
I'm using Windows 7 on my development system, but it should also work on XP so I cannot use the new IFileOperation interface.
Kind regards
I would ignore the shell API functions, and use MoveFileEx
or MoveFileWithProgress
directly.
精彩评论