Skip to content
⌘ NSIS Forum Archive

Problem with CopyFiles

11 posts

b179210#

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\*.*" "$TEMP\Backup\"
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 "$TEMP\Backup\*.*" "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
b179210#edited
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#
Rather than do a CopyFiles using wildcards perhaps you should use Locate and copy each file individually.

Stu
Afrow UK#
That is why you can use Locate. Do a recursive search through your source folder picking up any files.

Stu
b179210#
Ok, good idea 🙂 i'm searching function for do recoursive search.
Many thanks, i will tell you 😎
b179210#
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 👍

Bye bye
Afrow UK#
You can rename "Example6" to whatever you want (i.e. "LocateCallback") just to make the function mean something.

Stu
b179210#
Originally Posted by Afrow UK View Post
You can rename "Example6" to whatever you want (i.e. "LocateCallback") just to make the function mean something.

Stu
Yes, of course 😉