sc readfile, writefile and text - unreadable outputs

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

sc readfile, writefile and text - unreadable outputs

Post by neutrox »

I am seeing some discrepancies on sc readfile/writefile and sc text but it may be just me:

if <curitem> is the result of sc readurl saved as .txt,

Code: Select all

$a = readfile("<curitem>"); writefile("new.txt", $a);
gives different result from
text readfile("<curitem>");

TU for sc writefile won't do a difference here.

IOW when I pick sc text I have a read-able output, OTOH if I open a file created by sc readurl, sc readfile and writefile I just have a mess of words with no meaningful spacing at all.

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: sc readfile, writefile and text - unreadable outputs

Post by neutrox »

Guys, I badly need help on this.

The problem seems to be the lack of support of custom line feeds which are present on the sc text command so my suggestion is giving sc writefile the same ability. Sometimes it is great to have the original text formatting but in the case I explained in my previous post it is just too bad not being possible to convert documents to a different line feed.

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: sc readfile, writefile and text - unreadable outputs

Post by neutrox »

Code: Select all

writefile("d:\Downloads\Stuff\Offline\new.txt", readfile("d:\Downloads\Stuff\Offline\Offline Page.txt", t, , 65000), o, ); run "d:\Downloads\Stuff\Offline\new.txt";
I tried several encodings as attempts based on this page and xy documentation: http://msdn.microsoft.com/en-us/library ... epage.aspx

If I open the Offline Page.txt, select all, copy & paste it elsewhere other than notepad (wordpad, for instance), I get the desired spacing. As said, a simple text readfile(<curitem>); will do. But I need to fix those documents so they are eyes-friendly!

admin
Site Admin
Posts: 64838
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: sc readfile, writefile and text - unreadable outputs

Post by admin »

I don't think your description of the problem is complete enough for me to reproduce it. Please give me a copy-and-paste script that will create the error before my eyes.

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: sc readfile, writefile and text - unreadable outputs

Post by neutrox »

Code: Select all

writefile("ReadURL Test.text", readurl("http://www.youtube.com/watch?v=rte3kfzNXPg"));
then use this

Code: Select all

text readfile("ReadURL Test.text");
now open it with standard notepad:

Code: Select all

openwith notepad, "ReadURL Test.text";
What was a perfectly readable text-and-code now is just a heavy block of words due to lack of line feeds.

The problem is:
how to force sc writefile to write the necessary line feeds* info so the saved document
will store spacing in a format notepad will interpret line feeds like sc text does?

Because if I copy the output from sc text window into a new notepad document, then
notepad will correctly open it afterwards.
_________
*or sc readurl to correctly feed sc writefile, I don't know. But it does somehow, the line feeds are stored as sc text correctly interprets them. :roll:

admin
Site Admin
Posts: 64838
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: sc readfile, writefile and text - unreadable outputs

Post by admin »

Yawn. It's a UNIX file and XY says so in its preview Tab. Notepad is too stupid to handle UNIX. That's all.

PeterH
Posts: 2826
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: sc readfile, writefile and text - unreadable outputs

Post by PeterH »

I think "unix" is only LF (x'0a') for new lines?

Then you could change all LF to CRLF (x'0a' to x'0d0a').

Some editors (and other programs) understand both, some don't ...

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: sc readfile, writefile and text - unreadable outputs

Post by neutrox »

It seems that XYplorer won't allow use of "<cr>" and/or "<lf>" for search and replacement.

The following won't do it as well:

Code: Select all

[code]$base = readfile("<curitem>"); $lf =  chr(13).chr(10).chr(32).chr(32); replace $base, $base, "$lf", "<crlf>"; writefile("Text Fix.txt", $base);
[/code]

Code: Select all

[code]$base = readfile("<curitem>"); $lf =  chr(13).chr(10).chr(32); replace $base, $base, "$lf", "<crlf>"; writefile("Text Fix.txt", $base);
[/code]

Code: Select all

$base = readfile("<curitem>"); $lf =  chr(13).chr(10); replace $base, $base, "$lf", "<crlf>"; writefile("Text Fix.txt", $base);

Code: Select all

$base = readfile("<curitem>"); $lf =  chr(13); replace $base, $base, "$lf", "<crlf>"; writefile("Text Fix.txt", $base);
So how could I change those, PeterH?

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: sc readfile, writefile and text - unreadable outputs

Post by Stefan »

neutrox wrote:It seems that XYplorer won't allow use of "<cr>" and/or "<lf>" for search and replacement.
e.g.

Code: Select all

//$name = "<curname>";
     
   $data = readfile("<curitem>");
   ////match "\n" but not if there is an "\r" before:
   $data = regexreplace($data, "([^\r])\n", "$1<crlf>");
   text $data;
      
   //writefile($name . "_Win32.txt", $data);
Last edited by Stefan on 03 May 2012 10:56, edited 1 time in total.

highend
Posts: 14566
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: sc readfile, writefile and text - unreadable outputs

Post by highend »

Code: Select all

	$base = readfile("<curitem>");
	$base = regexreplace($base, "\n", "<crlf>");
	writefile("Text Fix.txt", $base);
One of my scripts helped you out? Please donate via Paypal

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: sc readfile, writefile and text - unreadable outputs

Post by Stefan »

highend wrote:

Code: Select all

	$base = readfile("<curitem>");
	$base = regexreplace($base, "\n", "<crlf>");
	writefile("Text Fix.txt", $base);
That will not only replace \n to \r\n
but also replace \r\n to \r\r\n
in files with mixed LE
or for files with windows LE only, processed by accident.

PeterH
Posts: 2826
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: sc readfile, writefile and text - unreadable outputs

Post by PeterH »

neutrox wrote:So how could I change those, PeterH?
Hey: nobody looked what you did wrong?

So: *what* did you try to replace???
I said x'0a', that's decimal 10, isn't it?

:arrow: I don't understand the idea of your first 3 examples.
But if, in the last version, you replace chr(13) with chr(10), you would be lucky.

(And if your scripts would have a better form people reading them would be more happy :roll: )

neutrox
Posts: 194
Joined: 05 Mar 2012 15:23

Re: sc readfile, writefile and text - unreadable outputs

Post by neutrox »

PeterH wrote: :arrow: I don't understand the idea of your first 3 examples.
But if, in the last version, you replace chr(13) with chr(10), you would be lucky.

(And if your scripts would have a better form people reading them would be more happy :roll: )
Those were attempts to get the replacement done.

I'll keep the readability on the back of my mind, sorry...... :oops:

Stefan, I understand your worry but highend's solution did he job.

For a reason I can't tell your script eliminates the closing ">" on several lines, thus damaging the original code.

PeterH
Posts: 2826
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: sc readfile, writefile and text - unreadable outputs

Post by PeterH »

neutrox wrote:
PeterH wrote: :arrow: I don't understand the idea of your first 3 examples.
But if, in the last version, you replace chr(13) with chr(10), you would be lucky.

(And if your scripts would have a better form people reading them would be more happy :roll: )
Those were attempts to get the replacement done.
Still I don't understand the idea...

If chr(13) isn't found, anything concatenated with chr(13) will not be found at all, isn't it?
(Imagine words: if a text doesn't contain "to" it will surely not contain "today"...)

So I'm afraid there is some problem in your understanding of replace()?
( :D note my writing of the function replace() :biggrin: )

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: sc readfile, writefile and text - unreadable outputs

Post by Stefan »

neutrox wrote:Stefan, I understand your worry but highend's solution did he job.
Right, it works for any line ender, "\n" and even "\r\n" or both mixed inside an file.
But the point is it should not work if you have already windows line enders "\r\n" because you get "\r\r\n" then.

For a reason I can't tell your script eliminates the closing ">" on several lines,
Oh silly me :cry: Of course :lol: it's wrong, i see now.
I have modified now my expression above. Sorry.

Post Reply