Jump to content

Unable to read text from file


Recommended Posts

I am attempting to read from a file to get a few fields out of using AutoIt. If I open this file with Notepad I can see the data I need to get out, a name and a number. I've written a little bit of the script that will open this file for reading and I've tried using FileReadLine(), FileRead() and _FileReadToArray to get the text out of it but the most I can get is the very first character. I've tried a variety of open methods as well but can't seem to get it to recognize anything more than the first character.

Any ideas on how I can get the text "SAMPLE" "REPORT" and "201438" out of this file progmatically? I have 700 files that I need to pull this data out of and then rename another file based on this information.

DAT62230.zip

Link to comment
Share on other sites

Well, it's a binary file, so in order to read it, you have to open file with binary mode switch.

As for getting some info out of that file, it's hard to tell without knowing the format of these *.4AT files.

That is, how to locate the info - are the offsets of these entries fixed, etc... Seeing another one or two (at least) of such files would clarify things a bit...

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

Well, it's a binary file, so in order to read it, you have to open file with binary mode switch.

As for getting some info out of that file, it's hard to tell without knowing the format of these *.4AT files.

Are the offsets of these entries fixed, etc... Seeing another one or two (at least) of such files would clarify things a bit...

I tried opening it with mode 16 but I still only can get the first character and that is all. I'll look into how the offsets are but this is the only file I have that does not have patient data in it so I can't post any more but I'll check on my own.

This is the code I'm using to open and try to read it currently.

#include <file.au3>
#Include <Array.au3>

;Set path for PatData from software
$DATDirectory="c:\PatData\"

;Put the file names of all files begnining with DAT into an array
$FileList=_FileListToArray($DATDirectory,"DAT*",1)
;Check for errors in the file list
If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
;_ArrayDisplay($FileList,"$FileList")

$file=FileOpen($DATDirectory & $fileList[1],16)
; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

;dim $fileread
;_FileReadToArray($DATDirectory & $fileList[1],$fileread)
;_ArrayDisplay($fileread)

$line = FileReadLine($file,1)
    MsgBox(0, "Line read:", $line)


$chars = FileRead($file)
    MsgBox(0, "Char read:", $chars)

FileClose($file)
Link to comment
Share on other sites

it appears that the files alll have the same number of characters in them so if I ignore the first 49 characters, then I should get the first name and if I go 31 characters past that, I'll have the last name.

Link to comment
Share on other sites

I am attempting to read from a file to get a few fields out of using AutoIt. If I open this file with Notepad I can see the data I need to get out, a name and a number. I've written a little bit of the script that will open this file for reading and I've tried using FileReadLine(), FileRead() and _FileReadToArray to get the text out of it but the most I can get is the very first character. I've tried a variety of open methods as well but can't seem to get it to recognize anything more than the first character.

Any ideas on how I can get the text "SAMPLE" "REPORT" and "201438" out of this file progmatically? I have 700 files that I need to pull this data out of and then rename another file based on this information.

Sure, can you please provide the exact data format/structure of that binary file?

EDIT: Maybe you should contact the manufacturer and ask for the format of *.4at files. http://www.biomedsys.com/Products_HolterMo...entury3000.aspx

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Not sure about the validity of this site http://www.iconv.com/file.htm but I entered in your sample *.4at file and it claims it's an *.lif format.

If this info is correct this site http://filext.com/file-extension/LIF says you most likely have a compressed format which you won't have much luck with in it's current state.

Link to comment
Share on other sites

If this info is correct

erm ... no.

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

The file extension changes. If the ID number of the patient is 622304, as it is in my example, then the file name is DAT62230.4at

The extension changes based on the last number of the ID.

These files are located in the programs directories and each one represents one patient. It may be compressed for all I know, but if I view the file with Notepad, I can see all of the data I really need out of it. Shouldn't I be able to view this with AutoIt as well or does it not work that way? All I need is the 622304 number and 201438 from the file so I can rename another file that is currently using the first number and needs to be named the second number.

Link to comment
Share on other sites

That sure gets me a lot further but it doesn't seem to be the right data. Running Evilertoaster's code I get #1: 800036 and #2:000000. I expanded how many characters it returns and none of the first 600 seem to be any part of the file I can see with notepad. I'm attaching a screenshot of what it shows if I have it display the first 600 characters. None of them seem to be what I'm looking for.

post-23260-1184012137_thumb.jpg

Link to comment
Share on other sites

Dont ask me why I was just messing around... but this

$file = FileOPen("DAT62230.4AT",16)
$data = StringReplace(FileRead($file),"00","")
$data= BinaryToString($data)
FileClose($file)
FileWrite("temp.txt",$data)

Makes a text file that you can read and gives you the same output as dragging the original file in to notepad (i think kind of), still full of crap but see what happens you can read the name etc

Edited by ChrisL
Link to comment
Share on other sites

What is BinarytoString? I get an error when I try to run it

RenamePDF.au3 (37) : ==> Unknown function name.:

$data= BinaryToString($data)

$data= ^ ERROR

>Exit code: 1 Time: 5.017

*edit* nevermind. Upgraded to new version and now I have the function.

Edited by Eagle117
Link to comment
Share on other sites

I upgraded to the latest now and I have the missing function but the code that Evilertoaster posted still shows the wrong number for number 1 and all zeros for number 2 even after the upgrade. ChrisL's code works to leave a text file with text in it but I haven't tested to make sure that the output is always the same length.

Link to comment
Share on other sites

Eagle117, use this code for the new version-

$file=FileOpen("DAT62230.4AT",4)
$read=BinaryToString(FileRead($file,258))
$number1=StringMid($read,3,6)
$number2=StringMid($read,252,6)
MsgBox(0,"Numbers-","#1: "&$number1&@CRLF&"#2: "&$number2)

That is working beautifully! Thank you! I was working on reading 6 characters at a time and checking if they were numbers and then accepting them and it was working until I hit a 5 digit number that was valid. Your way seems to work even better and with a quarter of the lines. I appreciate your time and effort of everyone in this thread.

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...