Jump to content

Recommended Posts

Posted

Hi,

I am new to AutoIt and this forum has already helped me a looot :x , 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 :P

Flok3r.

Posted (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 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

Posted (edited)

WOOOW, that was fast :x

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 by Flok3r
Posted

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

O my God yea!

Now it works :x

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

Posted

:P 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 :x

Thanks again for your help,

Flok3r

Posted (edited)

O my God yea!

Now it works :x

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

Extract 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 :P

Edited 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...