Sign in to follow this  
Followers 0
Nemcija

FileRead Bug

11 posts in this topic

Huhu,

I've got a big problem with FileRead()

For example i have got a File: (calculated by an other program)

[...] 07 7C 20 00 - 7D 60 A1 B0 - 12 41 D1 0D - 30 FF [...]

Now i read it out (FileRead) and write it down again into an other file.. (exactly the same data)

This will be the output:

[...] 07 7C 20 00 - 7D 60 A1 B0 - 12 41 D1 0D - 0A 30 FF [...]

Am I too stupid, or is it a bug?

I know 0D = @CR and 0D0A = @CRLF but i can't fix it by replacing all 0D0A's by 0D because if there is already a 0D0A it won't be changed to 0D0A0A ^^

Maybe this is something for the support forum, but maybe it is a bug. :whistle:

Thanks for reading.

Nemcija.


[url=www.vergessene-welt.de][/url]

Share this post


Link to post
Share on other sites



Did you try:

$string = StringReplace(FileRead('whereever.txt'), @CRLF, @CR)
?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

This is most obviously not a valid bug report. Moved to support.

Share this post


Link to post
Share on other sites

@SmOke_N:

This wouldn't work

FileRead converts:

[0D0A -> 0D0A] || CRLF -> CRLF (no change)

[0A -> 0A] || LF -> LF (no change)

but [0D -> 0D0A] || CR -> CRLF (big problem)

If I would try now to replace CRLF by CR I would replace the real CRLF, too. Do you now understand my problem?


[url=www.vergessene-welt.de][/url]

Share this post


Link to post
Share on other sites

nobody an idea? :whistle:


[url=www.vergessene-welt.de][/url]

Share this post


Link to post
Share on other sites

nobody an idea? :whistle:

You will have post an script plus input file that shows the exact problem if you want us to help you.

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Ok ok .. 3rd time i write it now

Inputfiledata (pe "input.file") in hexeditor:

[...] 07 7C 20 00 - 7D 60 A1 B0 - 12 41 D1 0D - 30 FF [...]

Now i read it out with Autoit (real code of the script more than 1000 lines long)

But i want to write an example to show it to you:

$filedata = fileread("input.file")
; [...]
; Work with a copy of $filedata
; Here i get an error at 0D when 0A has been added
;  ( not fixable in this codepart! )
; [...]
filewrite("output.file", $filedata)

Now i open "output.file" in a hexeditor:

[...] 07 7C 20 00 - 7D 60 A1 B0 - 12 41 D1 0D - 0A 30 FF [...]

FileRead converts:

[0D0A -> 0D0A]|| CRLF -> CRLF (no change)

[0A -> 0A] || LF -> LF (no change)

but [0D -> 0D0A] || CR -> CRLF (big problem)

If I try to replace CRLF by CR I would replace the real CRLF, too. Do you now understand my problem?

Edited by Nemcija

[url=www.vergessene-welt.de][/url]

Share this post


Link to post
Share on other sites

Ok ok .. 3rd time i write it now

I have read what you written.... and do not see an attached file ....

Maybe it would be nice if you supply the file you test with in stead of expecting it from us to create it .

anyways.. made this script which I think does what you want and do not see the problem... what hex Editor do you use ?:

#include<String.au3>
FileDelete("Test.hex")
FileDelete("Test2.hex")
$String = _HexToString("077C20007D60A1B01241D10D30FF")
Filewrite("Test.hex",$String)
$test = FileRead("Test.hex")
Msgbox(0,"debug",_StringToHex($test))
Filewrite("Test2.hex",$String)
$test = FileRead("Test2.hex")
Msgbox(0,"debug",_StringToHex($test))

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I m using Hex-Editor MX (v6) from Nextsoft.

in my script i use it like this:

$filehandle = FileOpen($file,0)
$filedata = FileRead($filehandle)
for $dataset = $start to $end
    $input = StringMid($filedata,StringInStr($filedata, "-Data-",0,1)+8+($dataset*11),11) ; StringInStr($filedata, "-Data-",0,1)+8 sets it to beginning. if you ask why "+8" -Data-=6 +CRLF=2 =8
    ;$dataset is the entrynumber
    $output = _StringToHex($input)
    FileWriteLine("Debug.txt",$input & " >>> " & $output) ; Debug
;[ ... ]
Next

here an example of my debugdata:

[...] (everything correctly)
 }`¡°a± >>> 070510007D60A1B01241B1
{P }`¡°aÑ >>> 077B50007D60A1B01241D1
|  }`¡°añ >>> 077C20007D60A1B01241D1
|  }`¡°b
 >>> 077C20007D60A1B012420D

|0 }`¡°b >>> 0A077C30007D60A1B01242
1~ð }`¡°b >>> 31077ED0007D60A1B01242
Ep }`¡°a >>> 014550007D60A1B0124110
P }`¡°a  >>> 019550007D60A1B0124120
[...]
You maybe see that there should be exactly 8 numbers before 7D6.

Edit:

I have found out something new.

before i read it out i write it down (seems to be logical :whistle: )

FileWrite already adds 0A if there is only a 0D

ok someone know how to fix this ? ^^

Edited by Nemcija

[url=www.vergessene-welt.de][/url]

Share this post


Link to post
Share on other sites

FileWrite already adds 0A if there is only a 0D

ok someone know how to fix this ? ^^

It does not as you can see in my example.... agree ?

I am willing to have a look at the issue when you provide everything that will allow me to replicate your problem.. the code you posted does not and you haven't attached the input file you use..


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Why are you using a Hex Editor and debug data?

You attempting read and exe and write it back out?


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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
Sign in to follow this  
Followers 0