PDA

View Full Version : Copy Folder Tree fails



Unregistered
06-20-2012, 01:54 AM
Hi

Copy folder tree fails with error 0. Calling GetLastError() from kernel32 returns 18 (ERROR_NO_MORE_FILES). This behaviour is new, it used to work until a couple of weeks. Seems to be related to FindNextFile() which i assume you're using inside copy folder tree.

Any ideas about this?

Regards

Gunnar

linder
06-20-2012, 02:07 AM
Gunnar,

A direct GetLastError() API call is not valid in this case because ERROR_NO_MORE_FILES might come from the function itself. It noticed that there are no more file to copy (process finished) and so the last error code might be 18.

Nothing changed in SetupBuilder that could cause this (last XCOPY file modification: Jan 03, 2011). Perhaps a virus-protection product "locks" one copy process or one of the files can't be copied because the target (or source) is locked, etc. But it's definitely not caused by one of the latest runtime modifications.

HTH,

Friedrich

linder
06-20-2012, 02:10 AM
BTW, the %_SB_RETURNEX% variable should hold the number of "processed" files. Compare this to the original folder tree and the number of files in the target folder.

Friedrich

Unregistered
06-20-2012, 02:37 AM
I manually copied the folder using xcopy, no problems there, no file locking or other problems. Obviously the copy folder tree command succeeds (all files are copied), though the return code still remains 0 and GetLastError() 18

linder
06-20-2012, 05:30 AM
See attached screenshots from a test:

c:\tree1 contains 40 files and 5 sub-folders. The script copies the folder tree from c:\tree1 to c:\tree2.

If the function succeeds, the %_SB_ERRORCODE% return value is nonzero.

This works as expected. SB_ERRORCODE is "1" and SB_RETURNEX is 40.

Then I locked one file in the target folder: SB_ERRORCODE is 0 and SB_RETURNEX is 39.

SB_ERRORCODE only returns 0 if a CopyFile Windows API failed.

Friedrich

Unregistered
06-20-2012, 05:59 AM
I copy a folder containing 692 files, SB_RETURNEX is 692 and SB_ERRORCODE is 0. Doing a folder compare shows no difference between source and destination (cleaned destination before). So, copy folder tree actually works although SB_ERRORCODE tells a different story. Strange. For now i use SB_RETURNEX to check if the operation succeeded.

Gunnar

linder
06-20-2012, 06:50 AM
SB_ERRORCODE retrieves the return code directly from the CopyFile Windows API. If the CopyFile function fails, the return value is zero (0). In other words, if SB_ERRORCODE is 0 in your case then CopyFile reported that the function did not succeed :)

Friedrich