Skip to content
⌘ NSIS Forum Archive

Renaming files using wildcard

3 posts

Guest#

Renaming files using wildcard

Noob question here... 🙂

Is it possible to copy files as a wildcard i.e. h*.txt and then rename them to h*.dat inside of the installer? I can do the first part with the CopyFiles command, but I haven't been able to figure out how to rename them using the same wildcard. The reason is, the source files that I would be copying over, can vary in their names, but they always start with the letter h.

Any ideas?

-M
Afrow UK#
You need to recursively loop through all files in the folder with FindFirst, FindNext and FindClose. You can check if the first character is "h" with StrCpy and StrCmp. You can also use StrCpy to get the last four characters (to check if it is ".txt")

-Stu
Instructor#
Name "Output"
OutFile "Output.exe"

!include "FileFunc.nsh"
!insertmacro Locate
!insertmacro GetBaseName

Section
StrCpy $R0 "C:\ftp" #Search in
StrCpy $R1 "C:\ftp_ren" #Copy to

${Locate} "$R0" "/L=F /M=h*.txt" "LocateCallback"

IfErrors 0 +2
MessageBox MB_OK "Error"
SectionEnd

Function LocateCallback
${GetBaseName} "$R7" $0
CopyFiles /SILENT $R9 $R1
Rename "$R1\$R7" "$R1\$0.dat"

Push 0
FunctionEnd