Archive: FileName as a variable while compile time


FileName as a variable while compile time
I add a file while compilation with the file command. The File has a Format like PatchXYZ-12345.exe ... is it possible to extract the 12345 string while compiling and use it as a variable inside the script?


You can't use it as a variable, since those operate at runtime. You can use it as a define (which operate at compiletime), but how to get the number I don't know. Perhaps make a bat file that passes both the filename and the scriptfile to the compiler? Not sure how to get a filename in a bat file either, though.


Take a look at the !searchparse command. For your example, you would use it like

# ${AFile} = PatchXYZ-12345.exe
!searchparse ${AFile} PatchXYZ- Serial .exe Unused
# ${Serial} = 12345
I'm not sure how you are adding the PatchXYZ-12345.exe file to the compile, but if you would create a defined value for it, you can use that define in the !searchparse command without extra work.
!define AFile PatchXYZ-12345.exe
File ${Afile}
!searchparse ${AFile} PatchXYZ- Serial .exe Unused
DetailPrint "${Serial} was compiled"

File "AnotherRelatedFile${Serial}.txt"

Maybe i told not clearly. I have File (it is only one) which is located inside a folder and which is added to installer while compiling ... maybe:

c:\files\Patch12345.exe

I add the file via this command line ...

File c:\files\*.exe

... to the installer.

How can i "scan" for the one filename inside c:\files and extract the 12345 from the File and put it inside a variable while compiling the script?

You'll probably need an external program to do this, as there are no NSIS commands that can do this as far as I know.


The wiki has an example showing how to call an external program when you compile your NSIS script:

http://nsis.sourceforge.net/Invoking...n_compile-time

The external program generates a file which is used when the main NSIS script is compiled.