Archive: Problems with CopyFiles

Problems with CopyFiles

sorry i'm new in working with nsis.

I want to copy files using CopyFiles:

CopyFiles "$INSTDIR\$Save" "$INSTDIR\saved"

$Save is a relative path like logs\log.txt

The command obove does not work!!! But if the command is:
CopyFiles "$INSTDIR\logs\log.txt" "$INSTDIR\saved" it WORKS!

I can not understand why! Why can't i use a Variable in the source?

Thanks for helping!


As far as I know CopyFiles is a normal runtime command so, unlike the File command, you should be able to use variables as parameters. If it's not working, most probably the value of the variable is wrong. Put this before the command to check:
MessageBox MB_OK "$INSTDIR\$Save"
It could also be that the $INSTDIR\saved doesn't exist yet, in which case it would copy it to a file called 'saved' inside $INSTDIR. First SetOutPath "$INSTDIR\saved" to create the directory.

Thank you very much!
I think the command CopyFiles also can't handle Variables as Parameters. If i use !define it works.

So far: I have another Problem.
I want to read out filenames (relative pathes) out of a file with FileRead,
like: FileRead $0 $Save (in a Loop)
So $Save contains the first line of a file and in my case it contains a relative path,
for example "logging.log".
If i compare $Save with "logging.log", it does not match.
Means: ${If} $Save == "logging.log" MessageBox "JA" ${EndIf} does not work!!!
Although DetailPrint $Save prints "logging.log"
I cannot understand why! I really need help! Maybe there is any Encoding Problem? What can i do?

Thank you for help!

Originally posted by nc10
${If} $Save == "logging.log" MessageBox "JA" ${EndIf} does not work!!!
You've got the LogicLib formatting wrong. Also the MessageBox is incorrect.
${If} $Save == "logging.log"
MessageBox MB_OK "JA"

But like I said, you can just use MessageBox MB_OK "$save"

Hey thanks for answer:
But i cannot see any difference?!?!
my code:
${If} $Save == "logging.log"
MessageBox MB_OK "Ja!"

(I only forgot to write MB_OK and the formatting in the post is wrong, in my code it is right)

What's wrong?

Please note that the If statement is case sensitive.
Also check if there are leading or trailing spaces in $Save.

The == and != operators are not case sensitive. S== and S!= are, however.


Ah, sorry, you're right, I was too quick on checking the wiki page.

Also check if there are leading or trailing spaces in $Save.
Thanks. Good Tip! Now i use a function which trims leading and trailing spaces. Now it works.
Now my Code:

FileOpen $0 "$INSTDIR\test_text.txt" r ; open and read line by line
IfErrors Done
FileRead $0 $Line
;DetailPrint "$Line!"
${un.Trim} $withoutSpaces $Line
Goto Loop
FileClose $0

The code works, but one more problem: At the end of the file, my loop always reads (and print) an empty line. I don't know why. I thought the loop only works until either a newline (or carriage return newline pair) occurs, or until a null byte is read (see docu).
Any idea?

Maybe obvious, but are you sure there's not actually a newline at the end of your file?