Jump to content

FileOpen does not work with unix files


pr1
 Share

Recommended Posts

Hello,

I have written an AutoIt program which loops through directories on the C drive, opens all readable files and searches for IP addresses in them.

Unfortunately, it can't read line-feed-terminated (ie, Unix) files, such as ImageMagick xml and html files (FileOpen returns -1). Changing the FileOpen flag from 0 to 128 (UTF8) makes no difference. Using the 4 flag (raw) seems to be the only solution, but looking for IP addresses in raw data is not really my cup of tea.

Does anyone have suggestions?

Many thanks.

pr1

Link to comment
Share on other sites

#include <String.au3>

$file = FileOpen("FilenameHere", 4)

If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$chars = FileRead($file,FileGetSize("FilenameHere"))
FileClose($file)

$string = StringReplace(String($chars),"0x","")
$string = StringReplace(_HexToString($string), Chr(255) & Chr(254), ""); _HexToString($string) This is the important part since Raw mode returns hex.
$string = StringReplace($string, Chr(0), "")

ConsoleWrite($string)

That should return a normal readable string again so you can use StringReqExp with the pattern "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}".

I'm not sure if you need all of the StringReplace lines for your file, however I did for mine.

Link to comment
Share on other sites

Well, AutoIt SHOULD be able to read them. Linefeed-files are nothing else than text with another separator.

So, say you can't read it in text mode, just binary?

1) Does this work: FileRead($Filepath)

2) or this?

$file = FileOpen("FilenameHere", 4)
$chars = BinaryToString(FileRead($file))
FileClose($file)
MsgBox($chars)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Well, AutoIt SHOULD be able to read them. Linefeed-files are nothing else than text with another separator.

So, say you can't read it in text mode, just binary?

1) Does this work: FileRead($Filepath)

2) or this?

$file = FileOpen("FilenameHere", 4)
$chars = BinaryToString(FileRead($file))
FileClose($file)
MsgBox($chars)
Many thanks to both of you for your help.

In fact, my problem was due to the fact that I didn't close the files after I opened them, not to line endings.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...