- NSIS Discussion
- Problems with CopyFiles
Archive: Problems with CopyFiles
nc10
20th June 2013 15:48 UTC
Problems with CopyFiles
Hi,
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!
NC10
MSG
21st June 2013 10:29 UTC
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.
nc10
26th June 2013 15:11 UTC
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!
MSG
26th June 2013 15:19 UTC
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"
${EndIf}
But like I said, you can just use MessageBox MB_OK "$save"
nc10
26th June 2013 15:47 UTC
Hey thanks for answer:
But i cannot see any difference?!?!
my code:
${If} $Save == "logging.log"
MessageBox MB_OK "Ja!"
${EndIf}
(I only forgot to write MB_OK and the formatting in the post is wrong, in my code it is right)
What's wrong?
jpderuiter
26th June 2013 22:00 UTC
Please note that the If statement is case sensitive.
Also check if there are leading or trailing spaces in $Save.
Afrow UK
27th June 2013 14:58 UTC
The == and != operators are not case sensitive. S== and S!= are, however.
Stu
jpderuiter
27th June 2013 22:15 UTC
Ah, sorry, you're right, I was too quick on checking the wiki page.
nc10
1st July 2013 09:00 UTC
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
Loop:
IfErrors Done
FileRead $0 $Line
;DetailPrint "$Line!"
${un.Trim} $withoutSpaces $Line
Goto Loop
Done:
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?
Thanks.
jpderuiter
1st July 2013 11:20 UTC
Maybe obvious, but are you sure there's not actually a newline at the end of your file?