b179210
5th May 2010 16:47 UTC
Problem with CopyFiles
Hi,
i have a problem with CopyFiles, i want copy (copy and then delete from "c:\test") some files from a folder to TEMP, but if error raised return back with copy from TEMP to "c:\test".
If a file is locked (i.e. "pdf") delete command from "c:\test" raised an error (but other files are deleted well), and when re-copy from TEMP to "c:\test" copy doesn't function (file locked) and no files are copied.
These are my steps:
CreateDirectory "$TEMP\Backup\"
CopyFiles "
C:Test*.*" "$TEMPBackup"
Retry:
ClearErrors
Delete "C:Test*.*"
IfErrors 0 NoError
MessageBox MB_RETRYCANCEL|MB_ICONQUESTION "Error during copy, retry?" IDRETRY Retry:
ClearErrors
SetOverwrite off ;i have tried with ifnewer-on-try, also
;Rollback - re-copy original file from $TEMP
CopyFiles "$TEMPBackup*.*" "C:Test"
IfErrors 0 NoError
MessageBox MB_ICONSTOP "Error during copy, stop"
Abort
NoError:
MessageBox MB_OK "Copy Ok"
>
Many thank for your help.
Mark
Afrow UK
5th May 2010 17:29 UTC
That is not a good way to do it. Have you tried moving the entire folder (Rename)?
Stu
b179210
6th May 2010 08:24 UTC
I have tried with "Rename" and "MoveFileFolder" functions, but error flag is raised because a file is locked.
My simple scenario is:
- copy all files from A folder to B folder with (or without) overwrite existing file
but if a file is locket in B folder error is raised and no files are copied, nor file not locked.
Many thanks
Afrow UK
6th May 2010 09:50 UTC
Rather than do a CopyFiles using wildcards perhaps you should use Locate and copy each file individually.
Stu
b179210
6th May 2010 10:40 UTC
Yes, the problem is that i have 31 files and every time these are different..:confused:
Afrow UK
6th May 2010 10:58 UTC
That is why you can use Locate. Do a recursive search through your source folder picking up any files.
Stu
b179210
6th May 2010 13:32 UTC
Ok, good idea :) i'm searching function for do recoursive search.
Many thanks, i will tell you :cool:
Afrow UK
6th May 2010 13:40 UTC
Locate is in the user manual.
Stu
b179210
18th May 2010 08:35 UTC
Finally i have finished my code using Locate function:
Section
StrCpy $R0"C:\ftp" ;Directory copy from
StrCpy $R1"C:\ftp2" ;Directory copy into
StrLen $R2 $R0
GetTempFileName$0
FileOpen $R3$0 w
${Locate} "$R0" "/L=FDE" "Example6"
FileClose $R3
IfErrors 0+2
MessageBox MB_OK 'error'
Exec '"notepad.exe" "$0"' ;view log
SectionEnd
>Function Example6
StrCpy$1 $R8 '' $R2
StrCmp $R6'' 0 +3
CreateDirectory '$R1$1\$R7'
goto end
CreateDirectory '$R1$1'
CopyFiles /SILENT $R9 '$R1$1'
IfFileExists '$R1$1\$R7' 0 +3
FileWrite $R3 "-old:$R9 -new:$R1$1\$R7 -success$\r$\n"
goto +2
FileWrite $R3 "-old:$R9 -new:$R1$1\$R7 -failed$\r$\n"
end:
Push $0
FunctionEnd
>
So, i can copy files and see log :)
Many thanks for your precious help :up:
Bye bye
Afrow UK
18th May 2010 12:27 UTC
You can rename "Example6" to whatever you want (i.e. "LocateCallback") just to make the function mean something.
Stu
b179210
20th May 2010 11:50 UTC
Originally posted by Afrow UK
You can rename "Example6" to whatever you want (i.e. "LocateCallback") just to make the function mean something.
Stu
Yes, of course ;)