WriteLn Command

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
nodochau
Pro Scripter
Posts: 135
Joined: Wed Jan 16, 2019 12:59 pm

WriteLn Command

Post by nodochau » Thu Feb 06, 2020 1:52 pm

Hello All,
Is there any parameter to be set so that when I execute WriteLn command and it just writes new lines in file. All the current lines in file will be truncated. By default when I execute WriteLn and it writes new lines below them.
Thank you for your help.

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: WriteLn Command

Post by Grovkillen » Thu Feb 06, 2020 1:58 pm

Just add %CRLF% to the string:

Code: Select all

Let>FILE_CONTENTS=this is row 1%CRLF%this is row 2
ConCat>FILE_CONTENTS,%CRLF%this is row 3
DeleteFile>%SCRIPT_DIR%\test.txt
WriteLn>%SCRIPT_DIR%\test.txt,,FILE_CONTENTS
The DeleteFile> command will not throw an error if the file doesn't exist so you can always have that one there if you want to over write an existing file.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: WriteLn Command

Post by Grovkillen » Thu Feb 06, 2020 2:16 pm

I re-read your post now. You should open the file in Notepad++ (or similar) and check the files format. It must be windows based for the new line to work properly.
Let>ME=%Script%

Running: 15.0.27
version history

nodochau
Pro Scripter
Posts: 135
Joined: Wed Jan 16, 2019 12:59 pm

Re: WriteLn Command

Post by nodochau » Thu Feb 06, 2020 4:28 pm

Thank you Grovkillen,
Is there anyway to not delete the file? Like C++ ofstream we don't need to delete it :)

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: WriteLn Command

Post by Grovkillen » Thu Feb 06, 2020 9:36 pm

Yep, just write to it without the delete file command. It will add a new line at the bottom of the file.
Let>ME=%Script%

Running: 15.0.27
version history

DreamTheater
Newbie
Posts: 19
Joined: Mon Oct 14, 2019 6:23 am

Re: WriteLn Command

Post by DreamTheater » Fri Feb 07, 2020 6:13 am

I'm not sure if I understand exactly what you mean, but if you don't want it to include the line break for each WriteLn> you can use:

Code: Select all

Let>WLN_NOCRLF=1
//Do stuff
Let>WLN_NOCRLF=0

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts