topten

Text file parameters

15 posts in this topic

Is it possible to set the text file parameters? For example in notepad.txt  I can manually set the patameters of page for printing 420x594 mm. How to do it programmatically

Share this post


Link to post
Share on other sites



What have you tried so far?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thank you, water for your response.

The thing is I am reading a text file line by line , encoding it base64 and then writing it to another text file. So in the text file it is supposed to be something like

"1"="asdfghasdfghasdfghasdfghasdfghasdfgahsdfghasd"

"2"="asdghjasdghajsdhgajsdhgasdjhgasdjhgasdjhgasdjhgasdjhg" etc

But as a result I am getting the situation when a very long line is broken into 2 or 3 lines and I am getting

"1"="asdfghasdfghasd

fghasdfghasdfghasdfgahsdfghasd"

"2"="asdghjasdghajsdhgajsdhgasdjhgasdjhga

sdjhgasdjhgasdjhg"

 

etc

The code is

$sFilePath = @DesktopDir & "outfile.txt"
$num = _FileCountLines ( $sFilePath )
Local $hFileOpen = FileOpen($sFilePath, $FO_READ)

  for $i = 1 to $num
    Local $sFileRead = FileReadLine($hFileOpen, $i)
    ConsoleWrite ($sFileRead & @CRLF)
    $base64encoded = _Base64Encode ($sFileRead, False)
    filewrite (@DesktopDir & "\infile.txt",  '"'&$i & '"="' & $base64encoded & '"' & @CRLF)
  next

I think, may be this line breaking is happening, because the width of txt file innitially set?

Share this post


Link to post
Share on other sites

You mean: Even with ConsoleWrite you get 2 or 3 lines which are shorter than the maximum width of the SciTE output pane?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Yes, right

Sometimes I am getting in 3 lines, something like

"1"="asdfgha

sdfghasdfghasdfghasdfgh

asdfgahsdfghasd"

Instead of

"1"="asdfghasdfghasdfghasdfghasdfghasdfgahsdfghasd"

 

Share this post


Link to post
Share on other sites

If to be more precise in consolewrite I am geting such things

"7"="asdasdasdasdasdasdasdasdasdasd"          
"8"="sdftrtytyiyuiyjghnfghfghrtyrgdfsdfw
asdasdasd"            asdasdasdasdasertertertrthgbgfgdf
"9"="qweasdxcvdfgrtyfghvbnghryfgbcv"

Share this post


Link to post
Share on other sites

According to wikipedia there seems to be a maximum line length of 76 bytes for mime before a CRLF is being inserted.

https://en.wikipedia.org/wiki/Base64#MIME


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I see. What I am doing now - I am writing these into txt file and then manually change the "linebreaks on/off" parameter in notepad.  When I manually changes this then all lines are going  without breaks.

I wonder, Can I do anything about that programmatically

 

Share this post


Link to post
Share on other sites

I'm not sure it is sensible to have your script and the base64 encoding function insert CRLF into the result.
I think you should read the while file using FileRead (ignoring CRLF), encode it and then write the result to the output file without adding a CRLF.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

That's the problem. The file should have the structure

"1"="...................."

"2"="...................." etc

If it gets the structure like a

"1"=".....................................

....................

......"

"2"="..........................

............

...."

It will fail. It is a .reg file

:)

Share this post


Link to post
Share on other sites

I tried to remove @CRLF- after that everythin is becoming even more messy

Share this post


Link to post
Share on other sites

But what is interesting.

$hFileOpen2 = @DesktopDir & "\patchcreating\in.txt"
$hFileOpen3 = @DesktopDir & "\patchcreating\out.txt"

$sFileRead = FileReadLine($hFileOpen2, 1)
$sFileRead2 = FileReadLine($hFileOpen2, 2)
FileWriteLine($hFileOpen3, $sFileRead& $sFileRead2)

When I read the ready file's line 1 and line 2 and then write them together into another file they are written into one line as it is supposed

 

Share this post


Link to post
Share on other sites

That's what I said: Looks like the encoding routine inserts the CRLF.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I have designed quite a hackish way to fix it though

$source = FileRead (@DesktopDir & "in.txt")

$text =  StringRegExp($source, '(?s)="(.*?)"', 3)

for $i = 0 to UBound ($text)-1
$string = StringStripWS($text[$i],8)
filewrite (@DesktopDir & "\out.txt",  '"'&$i+1 & '"="' & $string & '"' & @CRLF)


next

Have to create another file and after that remove those whitespaces. Works, but still not solved, why can't I just directly write into innitial file without those line breaks

Share this post


Link to post
Share on other sites

You are right, Water. It is the encoding routine, that is inserting CRLF, I found it in the udf

Share this post


Link to post
Share on other sites

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