Eagle117 Posted July 5, 2007 Posted July 5, 2007 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
Siao Posted July 5, 2007 Posted July 5, 2007 (edited) 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 July 5, 2007 by Siao "be smart, drink your wine"
Eagle117 Posted July 5, 2007 Author Posted July 5, 2007 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)
Eagle117 Posted July 5, 2007 Author Posted July 5, 2007 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.
Eagle117 Posted July 9, 2007 Author Posted July 9, 2007 Anyone able to help me read the text in this file? Opening it as a binary file hasn't change anything yet.
weaponx Posted July 9, 2007 Posted July 9, 2007 Is that file a compressed DAT tape file? Are you sure it's not an archive of multiple files?
/dev/null Posted July 9, 2007 Posted July 9, 2007 (edited) 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 July 9, 2007 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 *
weaponx Posted July 9, 2007 Posted July 9, 2007 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.
/dev/null Posted July 9, 2007 Posted July 9, 2007 If this info is correcterm ... 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 *
Eagle117 Posted July 9, 2007 Author Posted July 9, 2007 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.
evilertoaster Posted July 9, 2007 Posted July 9, 2007 (edited) If you're sure the offsets dont change- $file=FileOpen("DAT62230.4AT",4) $read=FileRead($file,258) $number1=StringMid($read,3,6) $number2=StringMid($read,252,6) MsgBox(0,"Numbers-","#1: "&$number1&@CRLF&"#2: "&$number2) It works on the sample file you provided. Edited July 9, 2007 by evilertoaster
Eagle117 Posted July 9, 2007 Author Posted July 9, 2007 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.
ChrisL Posted July 9, 2007 Posted July 9, 2007 (edited) 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 July 9, 2007 by ChrisL [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire
evilertoaster Posted July 9, 2007 Posted July 9, 2007 Eagle117, what version of autoit are you using?
Eagle117 Posted July 9, 2007 Author Posted July 9, 2007 (edited) 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 July 9, 2007 by Eagle117
Eagle117 Posted July 9, 2007 Author Posted July 9, 2007 Eagle117, what version of autoit are you using?Looks like v3.2.4.0 according to the help files.
evilertoaster Posted July 9, 2007 Posted July 9, 2007 (edited) try getting the latest version (v3.2.4.9). Your version is reading binary strings in a differnt way it seems. Edited July 9, 2007 by evilertoaster
Eagle117 Posted July 9, 2007 Author Posted July 9, 2007 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.
evilertoaster Posted July 9, 2007 Posted July 9, 2007 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)
Eagle117 Posted July 9, 2007 Author Posted July 9, 2007 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now