PDA

View Full Version : XCopyFile Question



adampr6
08-04-2004, 04:42 PM
How do I prevent XCopyFile from overwriting a destination file if it's already there? I know I could check if the file exists first, but I want to use XCopyFile to copy a directory of about 1000 files and don't want to have to write a loop to do this if it's possible.

Thanks,

Adam

djvdjv
08-05-2004, 09:12 AM
XCopyFile ("*.*", "*.*", COMP_UPDATE_DATE | COMP_UPDATE_VERSION);

Will only replace files with earlier date and/or previous version.

Is that what you were looking for?

adampr6
08-05-2004, 10:50 AM
No. The problem is the files I'm trying to copy will always have a newer date than the ones they would be compared against. I simply do not want to copy the file if it's there already, regardless of date, version, size, or any other property.

djvdjv
08-05-2004, 11:00 AM
Lot's a luck with that one....

adampr6
08-05-2004, 11:04 AM
I guess I'll just have to do it manually in a loop, eh.

djvdjv
08-05-2004, 11:09 AM
Unless you can establish your files in a Feature and take advantage of the "NEVER OVERWRITE files, even if their version or date is older" option.

Which means you would not be using XCopyFile to transfer your files.

adampr6
08-05-2004, 11:14 AM
That won't work for me either. The files are in a feature..they get copied to a temporary location on install. I then perform some processing on the files and copy them to their final location. The problem is that some of the files in the final location can get modified by other means and if a user re-installs the app or adds other features to install, I don't want to overwrite the modified files.

adampr6
08-05-2004, 01:32 PM
This does what I want:

//build a list of files to copy
dataFiles = ListCreate(STRINGLIST);

//Get first file

LongPathToQuote(tmpPath,FALSE);
nResult = FindAllFiles(tmpPath,"*.*", sMatchingFilename, RESET);


while (nResult = 0)
ListAddString(dataFiles,sMatchingFilename,AFTER);
nResult = FindAllFiles(tmpPath,"*.*", sMatchingFilename, CONTINUE);
endwhile;

//iterate through list and check for existance of file in destination
nResult = ListGetFirstString(dataFiles,sMatchingFilename);
while (nResult != END_OF_LIST)
//strip off file name
ParsePath(sFilename,sMatchingFilename, FILENAME);

//if file doesn't exist, copy it over
if (!Is(FILE_EXISTS,thePath^sFilename))
then
nResult = XCopyFile(sMatchingFilename,
thePath,
COMP_NORMAL);

endif;

if (nResult = 0) then
//delete temp file
DeleteFile(sMatchingFilename);
endif;
nResult = ListGetNextString(dataFiles,sMatchingFilename);
endwhile;

//delete the temporary directory
nResult = DeleteDir(tmpPath,ALLCONTENTS);

//free memory
ListDestroy(dataFiles);

Ingreyd
08-12-2004, 08:40 PM
I had the same issue in an install a wrote a while ago. I got around the problem by using the COM FileSystem object.

If I can dig out the code I will post.