Old 20th June 2013, 15:48   #1
nc10
Junior Member
 
Join Date: Jun 2013
Posts: 16
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
nc10 is offline   Reply With Quote
Old 21st June 2013, 10:29   #2
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
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.
MSG is offline   Reply With Quote
Old 26th June 2013, 15:11   #3
nc10
Junior Member
 
Join Date: Jun 2013
Posts: 16
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!
nc10 is offline   Reply With Quote
Old 26th June 2013, 15:19   #4
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Quote:
Originally Posted by nc10 View Post
${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"
MSG is offline   Reply With Quote
Old 26th June 2013, 15:47   #5
nc10
Junior Member
 
Join Date: Jun 2013
Posts: 16
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?
nc10 is offline   Reply With Quote
Old 26th June 2013, 22:00   #6
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
Please note that the If statement is case sensitive.
Also check if there are leading or trailing spaces in $Save.
jpderuiter is offline   Reply With Quote
Old 27th June 2013, 14:58   #7
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
The == and != operators are not case sensitive. S== and S!= are, however.

Stu
Afrow UK is offline   Reply With Quote
Old 27th June 2013, 22:15   #8
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
Ah, sorry, you're right, I was too quick on checking the wiki page.
jpderuiter is offline   Reply With Quote
Old 1st July 2013, 09:00   #9
nc10
Junior Member
 
Join Date: Jun 2013
Posts: 16
Quote:
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.
nc10 is offline   Reply With Quote
Old 1st July 2013, 11:20   #10
jpderuiter
Major Dude
 
Join Date: Feb 2007
Posts: 672
Maybe obvious, but are you sure there's not actually a newline at the end of your file?
jpderuiter is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump