I need to move the contents of a directory (within which there are directories and files, each of which can contain directories and/or files, etc). I need to not move it en masse, but one at a time, as I need to perform an extra operation on each file that I move.
I need to retain the folder structure as well. Currently I have this, which a) doesn't work properly, and b) doesn't retain the folder structure:
For completeness, here is the COPY_FILE macro:
Push $1
Push $8
Push $9
StrCpy $9 "$INSTDIR\scripts-temp\"
startSearch:
FindFirst $0 $1 "$9\*"
StrCpy $8 "0"
loop:
StrCmp $1 "" dirdone
IfFileExists "$9\$1\*.*" IsDir NotDir
IsDir:
StrCmp $1 "." bleh
StrCmp $1 ".." bleh
Push "$9$1\"
IntOp $8 $8 + "1"
Goto bleh
NotDir:
!insertmacro WRITE_TO_MAIN_LOG "Copying file $9$1 to $INSTDIR\scripts\" "**"
!insertmacro COPY_FILE $9$1 "$INSTDIR\scripts\"
bleh:
FindNext $0 $1
Goto loop
dirdone:
IntCmp $8 "0" done
IntOp $8 $8 - 1
Pop $9
Goto startSearch
done:
Pop $9
Pop $8
Pop $1
Thanks guys, sorry to lumber you with a nasty one like this 🙂
!macro COPY_FILE OLD_FILEPATH NEW_FILEPATH
ClearErrors
Rename "${OLD_FILEPATH}" "${NEW_FILEPATH}"
IfErrors +4
!insertmacro WRITE_TO_MAIN_LOG "Wrote file ${NEW_FILEPATH}" "**"
!insertmacro WRITE_TO_FILELIST_LOG "${NEW_FILEPATH}"
Goto +2
!insertmacro WRITE_TO_MAIN_LOG "Unable to copy file '${OLD_FILEPATH}' to '${NEW_FILEPATH}'" "EE"
!macroend
-rob-