views:

89

answers:

1

Hi,

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 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

+1  A: 

I would ignore the shell API functions, and use MoveFileEx or MoveFileWithProgress directly.

Jerry Coffin
Does this solve the network path problem?
Christian Metzler
@Coco: I'm not entirely sure whether it does or not -- but my thought was that it would be pretty quick/easy to find out.
Jerry Coffin
I will test it tomorrow and write my feedback.
Christian Metzler
MoveFile solves the problem. Thank you!
Christian Metzler