Skip to content
⌘ NSIS Forum Archive

Moving files with wildcard names in loop

5 posts

MyPC8MyBrain#

Moving files with wildcard names in loop

HI guys 🙂
i need little help creating a loop that moves files from one dir to another,
after changing dir i want to find all files starting with ftm*.txt
and move them to another dir (keeping the original file names),

i thought this should work; obviously it doesn't 😕

          ClearErrors
          setoutpath "$INSTDIR\"
          ${DoUntil} ${Errors}
          ${If} ${FileExists} ftm*.txt pop $1
          rename "$1" "$INSTDIR\BAK\"
          ${EndIf}
          ${Loop} 
im probably mixing things there but not sure what,

TIA
Chris
MyPC8MyBrain#
Thank you Anders 🙂
since i posted this i come across something i think you should recognize,
it is perfect for what im looking for if i can only figure out how to set its starting root dir instead of drive root,

Unicode False
Unicode true
Function ProcessTextFiles
Exch $0
Push $1
Push $2
FindFirst $1 $2 "$0\ftm*.txt"
loop:
    IfErrors end
    DetailPrint 'Found "$0\$2"'
    FindNext $1 $2
    goto loop
end:
FindClose $1
FindFirst $1 $2 "$0\*.*"
dirloop:
    IfErrors dirend
    IfFileExists "$0\$2\*.*" 0 dirnext
    StrCmp $2 "." dirnext
    StrCmp $2 ".." dirnext
    Push "$0\$2"
    call ${__FUNCTION__}
dirnext:
    FindNext $1 $2
    goto dirloop
dirend:
FindClose $1
Pop $2
Pop $1
Pop $0
FunctionEnd
section
push "$InstDir"
call ProcessTextFiles
sectionend 
how do i change starting dir in this little gem?
if i add the path like so
FindFirst $1 $2 "$0\D:\Users\Administrator\Desktop\test\*.txt" 
it stops iterating through sub folders 🙁

TIA
Chris
JasonFriday13#
In the section down the bottom of that code, instead of $instdir put the path you want to search, ie push "$DESKTOP\test".
MyPC8MyBrain#
YaY \ o / it works
Thank you Jason!

i also managed to get the first bit i asked about working with your advice Anders,
Thank you both Anders and Jason <3

ATB
Chris