Technical support and scripting issues
Moderators: JRL, Dorian (MJT support)
-
armsys
- Automation Wizard
- Posts: 1108
- Joined: Wed Dec 04, 2002 10:28 am
- Location: Hong Kong
Post
by armsys » Fri Nov 07, 2014 1:36 am
Referring to
why does it always create a 2-byte empty text file?
Is it possible to a zero-byte empty text file by WriteLn?
To bypass the above limitation, I use
Run>cmd.exe /C copy NUL "c:\Temp\Temp.docx" instead.
-
JRL
- Automation Wizard
- Posts: 3532
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Fri Nov 07, 2014 2:19 am
hi Armstrong,
By default WriteLn> adds a carriage return and line feed every time it writes a line. To avoid this you set the system variable WLN_NOCRLF to 1. See help for WriteLn>.
Code: Select all
Let>WLN_NOCRLF=1
WriteLn>c:\temp\test.txt,result,
-
armsys
- Automation Wizard
- Posts: 1108
- Joined: Wed Dec 04, 2002 10:28 am
- Location: Hong Kong
Post
by armsys » Fri Nov 07, 2014 8:48 am
Hi JRL,
Thanks for your reply.
Before posting my question, I did try out your trick amongst others in vain.
It always creates a 2-byte text file.
And I re-test your script and confirm the file size is still 2 bytes.
Have you tested your script?
-
hagchr
- Automation Wizard
- Posts: 331
- Joined: Mon Jul 05, 2010 7:53 am
- Location: Stockholm, Sweden
Post
by hagchr » Fri Nov 07, 2014 9:58 am
Hi, When I try JRL's code I get 0kb. My understanding is that if the file already exists then it will append to it. Did you try to delete the test file before running the new code?
-
Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
-
Contact:
Post
by Marcus Tettmar » Fri Nov 07, 2014 10:11 am
WriteLn means "Write A Line". A line has a line break. That's what you are seeing.
JRL's method switches off the line break (so it's no longer writing a new line) and so you don't see the line ending chars.
-
armsys
- Automation Wizard
- Posts: 1108
- Joined: Wed Dec 04, 2002 10:28 am
- Location: Hong Kong
Post
by armsys » Fri Nov 07, 2014 9:50 pm
Hi Hagchr & Marcus,
Thanks for your help.
Repeatedly testing out the following script confirms a 2-byte text file as indicated in the Explorer:
Code: Select all
DeleteFile>C:\Temp\Temp.docx
IfNotFileExists>C:\Temp\Temp.docx
Let>WLN_NOCRCRLF=1
WriteLn>C:\Temp\Temp.docx,wres,
Endif
-
JRL
- Automation Wizard
- Posts: 3532
- Joined: Mon Jan 10, 2005 6:22 pm
- Location: Iowa
Post
by JRL » Fri Nov 07, 2014 10:25 pm
That's because your global variable WLN_NOCRCRLF does not exist. Too many CRs in it. Change it to WLN_NOCRLF. the following code will also tell you the size of the file so you won't have to take any extra steps to see how big the file isn't.
Code: Select all
DeleteFile>C:\Temp\Temp.docx
IfNotFileExists>C:\Temp\Temp.docx
Let>WLN_NOCRLF=1
WriteLn>C:\Temp\Temp.docx,wres,
Endif
FileSize>C:\Temp\Temp.docx,vBytes
MDL>vBytes
-
armsys
- Automation Wizard
- Posts: 1108
- Joined: Wed Dec 04, 2002 10:28 am
- Location: Hong Kong
Post
by armsys » Sat Nov 08, 2014 7:12 am
Hi JRL,
You're correct. I made a variable typo of WLN_NOCRLF. Yes, your code produces a text files of zero bytes.
Thank you all.