Flok3r Posted January 16, 2011 Posted January 16, 2011 Hi, I am new to AutoIt and this forum has already helped me a looot , but this time i need help. I want to write a .bat file mirroring 2 folders and execute it after a button has been pressed. Its content should look like: cd /d %~dp0 robocopy "F:\" D:\MyRescue\ /L /TEE /ETA /TS /R:5 /W:1 /ZB /MIR /COPYALL /LOG:"C:\Users\Flok3r\Desktop\MyScript\mirrorlog.txt" /XD "$RECYCLE.BIN" "RECYCLER" "System Volume Information\" "_MyFiles\Games" (the part after "cd.." is one line) But when autoit runs (everything is one line): FileWrite('mirror.cmd', 'cd /d %~dp0' & @CR & 'robocopy "' & $mrp & '" ' & $mrd & ' /L /TEE /ETA /TS /R:5 /W:1 /ZB /MIR /COPYALL /LOG:"' & @ScriptDir & '\mirrorlog.txt"' & ' /XD ' & '"\$RECYCLE.BIN"' & ' "RECYCLER"' & ' "System Volume Information\"' & ' "\_MyFiles\Games"') The content of the mirror.cmd is: cd /d %~dp0 robocopy "F:\ " D:\MyRescue\ /L /TEE /ETA /TS /R:5 /W:1 /ZB /MIR /COPYALL /LOG:"C:\Users\Flok3r\Desktop\MyScript\mirrorlog.txt" /XD "\$RECYCLE.BIN" "RECYCLER" "System Volume Information\" "\_MyFiles\Games" Where do these 2 linebreaks come from, how can i avoid that? It is probably a simple mistake, but I didnt find anything about that special case, neither in the web nor in this helpful forum. Thanks in advance, every advice is welcome ;D.. and sorry for my ignorance in case i missed something really simple Flok3r.
kylomas Posted January 16, 2011 Posted January 16, 2011 (edited) Flok3r, wherever you want to insert a line break use the macro @CRLF, not @CR e.g. "FileWrite('mirror.cmd', 'cd /d %~dp0' & @CRLF & 'robocopy "' & $mrp & '" ' & $mrd &..." kylomas Edit: also watch your single and double quotes Edit2: your "&" after $mrp may be misplaced. Edit3: Flok3r, sorry about that, your "&"'s need to occur outside of the quotes..@CR may work, don't know I always use @CRLF. Edited January 16, 2011 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Flok3r Posted January 16, 2011 Author Posted January 16, 2011 (edited) WOOOW, that was fast Thanks for your reply, yea, i know that with @CRLF, i tried it before, but i changed nothing. My Problem is, that these breaks DO appear, i.e. i dont want them at all and unfortunately i dont know where they come from. I spend some time until i figured out how to use quotes in quotes, that is not the point, because, regarding to the output of autoit, all the double quotes inside the single ones are written as intended. What do you mean by saying "misplaced"? Is that "&" responsible for the breaks? Actually, if i wanted to insert a space and quote sign, i would have to separe the 2 variables with &, or not? Flok3r Actually they arent in the quotes (scithe shows them coloured ;D), the singlequotes around the '" ' are supposed to write space and ". Edited January 16, 2011 by Flok3r
UEZ Posted January 16, 2011 Posted January 16, 2011 Try this: $filename = @ScriptDir & "\mirror.cmd" $hFile = FileOpen($filename, 2) FileWriteLine($hFile, '@echo off') FileWriteLine($hFile, 'cd /d %~dp0') FileWriteLine($hFile, 'robocopy "F:\" D:\MyRescue\ /L /TEE /ETA /TS /R:5 /W:1 /ZB /MIR /COPYALL /LOG:"C:\Users\Flok3r\Desktop\MyScript\mirrorlog.txt" /XD "$RECYCLE.BIN" "RECYCLER" "System Volume Information\" "_MyFiles\Games"') FileClose($hFile) Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Flok3r Posted January 16, 2011 Author Posted January 16, 2011 O my God yea! Now it works As I said, the solution is very simple. Thanks, but is that a bug, or why else the behaviour of FileWrite and FileWriteLine are different here? Flok3r
kylomas Posted January 16, 2011 Posted January 16, 2011 Flok3r, yea, fast but not accurate, my apologies...UEZ has the solution, as usual.. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Flok3r Posted January 16, 2011 Author Posted January 16, 2011 The main thing is, that i got the solution.. and that sooo fast, never expected that, this is really a great forum!! @UEZ: By the way: Ich bin übrigens auch Deutscher Thanks again for your help, Flok3r
UEZ Posted January 16, 2011 Posted January 16, 2011 (edited) O my God yea!Now it works As I said, the solution is very simple. Thanks, but is that a bug, or why else the behaviour of FileWrite and FileWriteLine are different here?Flok3rExtract from help file:FileWriteLine ( "filehandle/filename", "line" )filehandle/filename: The handle of a file, as returned by a previous call to FileOpen. Alternatively, you may use a string filename as the first parameter.line: The line of text to write to the text file. If the line does NOT end in @CR or @LF then a DOS linefeed (@CRLF) will be automatically added.Gruß,UEZ Edited January 16, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Flok3r Posted January 16, 2011 Author Posted January 16, 2011 Hm A helpful AutoIt geek said once: "Never say never!".. But interesting. Thanks again and have a nice weekend Flok3r
Flok3r Posted January 16, 2011 Author Posted January 16, 2011 Hm A helpful AutoIt geek said once: "Never say never!".. But interesting. Thanks again and have a nice weekend Flok3r
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now