TheDcoder Posted February 13, 2016 Share Posted February 13, 2016 (edited) Hello! I am having problem with using file read... Here is my code: #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local Const $CHUNK = 1024 Local $hFile = FileOpen(@ScriptDir & '\test.bin', $FO_APPEND) Local $iCurrentPos = 0 Do $iCurrentPos += $CHUNK $bFileSetPos = FileSetPos($hFile, $iCurrentPos, $FILE_END) $vData = FileRead($hFile) $vData = BinaryToString($vData) MsgBox(0, 0, $vData) $iStringPos = StringInStr($vData, "Test", $STR_NOCASESENSEBASIC) Until Not ($iStringPos = 0) Or $bFileSetPos = False FileClose($hFile) MsgBox($MB_OK, "Success", $iStringPos) Here is the 6 MB file: <Attachment Deleted> Thanks in Advance! TD Edited February 13, 2016 by TheDcoder Appended [Solved] to title & deleted attachment EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
water Posted February 13, 2016 Share Posted February 13, 2016 You have to define the number of bytes to read in FileRead as well. Else you read the whole file every time. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
TheDcoder Posted February 13, 2016 Author Share Posted February 13, 2016 @water Huh? I remember that FileRead reads from the position set by FileSetPos, my previous version of code just did that. Even if it did read the whole file, I think it would be easy to store 6 MB of data... This is my test script which I use to read the whole file: ConsoleWrite(FileRead(@ScriptDir & '\test.bin')) MsgBox(0,0,0) 1 hour ago, water said: You have to define the number of bytes to read in FileRead as well I tried that now, I set the number of bytes to read to $iCurrentPos, Now for some reason the script is looping indefinitely. TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
TheDcoder Posted February 13, 2016 Author Share Posted February 13, 2016 @water Huh? I remember that FileRead reads from the position set by FileSetPos, my previous version of code just did that. Even if it did read the whole file, I think it would be easy to store 6 MB of data... This is my test script which I use to read the whole file: ConsoleWrite(FileRead(@ScriptDir & '\test.bin')) MsgBox(0,0,0) 1 hour ago, water said: You have to define the number of bytes to read in FileRead as well I tried that now, I set the number of bytes to read to $iCurrentPos, Now for some reason the script is looping indefinitely. TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
water Posted February 13, 2016 Share Posted February 13, 2016 (edited) Can you please describe what you try to do? Now you Open the file in write/append mode - but you only read the content You use FileSetPos from the end of the file - do you really try to read the file from end to start? You increment $iCurrentPos - but my understanding is that this should be a negative number for FileSetPos from the end of the file You always read the file from the set position to the end - the longer you loop the more data you read Error checking is not done when an error could occur (after FileSetPos or FileRead) - so you might process data in an inconsistant state Edited February 13, 2016 by water TheDcoder 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
TheDcoder Posted February 13, 2016 Author Share Posted February 13, 2016 3 minutes ago, water said: Can you please describe what you try to do? I am trying to read the footer of a file (in this case "Test" indicates where the footer starts from) 5 minutes ago, water said: Open the file in write/append mode - but you only read the content The code is from a function in my original code, I returned the read data. 5 minutes ago, water said: You use FileSetPos from the end of the file - do you really try to read the file from end to start? Yep, it is necessary to read the footer 6 minutes ago, water said: You increment $iCurrentPos - but my understanding is that this should be a negative number to read from the end of the file Silly me! That fixed the problem Thanks water! You solved my problem by asking questions! That is simply great! EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
TheDcoder Posted February 13, 2016 Author Share Posted February 13, 2016 This is the code which worked for me : #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> Local Const $CHUNK = 1024 Local $hFile = FileOpen(@ScriptDir & '\test.bin', $FO_APPEND) Local $iCurrentPos = 0 Local $bFileSetPos = True Do $iCurrentPos -= $CHUNK $bFileSetPos = FileSetPos($hFile, $iCurrentPos, $FILE_END) $vData = FileRead($hFile, $iCurrentPos) $vData = BinaryToString($vData) $iStringPos = StringInStr($vData, "Test", $STR_NOCASESENSEBASIC) Until Not ($iStringPos = 0) Or $bFileSetPos = False FileClose($hFile) MsgBox($MB_OK, "Success", $iStringPos) But I still don't understand why there was a memory allocation error in my faulty code EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
water Posted February 13, 2016 Share Posted February 13, 2016 Glad the problem could be solved But I still think it is a lot of overhead to check a 6MB file My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
TheDcoder Posted February 13, 2016 Author Share Posted February 13, 2016 Just now, water said: lot of overhead to check a 6MB file Any suggestions? EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
water Posted February 13, 2016 Share Posted February 13, 2016 Read the file in one go. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
TheDcoder Posted February 13, 2016 Author Share Posted February 13, 2016 @water . I normally process larger files, this was tiny compared to them EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
water Posted February 13, 2016 Share Posted February 13, 2016 Ah, new information My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
LarsJ Posted February 13, 2016 Share Posted February 13, 2016 (edited) If you need the footer only, then read the file from the end. Edited February 13, 2016 by LarsJ Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
TheDcoder Posted February 13, 2016 Author Share Posted February 13, 2016 Just now, LarsJ said: If you need the footer only, the read the file from the end. ? EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
LarsJ Posted February 13, 2016 Share Posted February 13, 2016 My grandmother can code that - while she is knitting at the same time. She can multitask. You have to figure that out yourself young man. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
TheDcoder Posted February 13, 2016 Author Share Posted February 13, 2016 11 minutes ago, LarsJ said: My grandmother can code that Your grandma is Augusta Ada!? EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
water Posted February 13, 2016 Share Posted February 13, 2016 No, his grandmother is a woman. And women are able to multitask. At least that's what they try to tell us. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted February 13, 2016 Share Posted February 13, 2016 Guess what I found in the help file "A count value that is too large can lead to AutoIt stopping with a memory allocation failure." My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
TheDcoder Posted February 13, 2016 Author Share Posted February 13, 2016 Just now, water said: No, his grandmother is a woman https://en.wikipedia.org/wiki/Ada_Lovelace EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
TheDcoder Posted February 13, 2016 Author Share Posted February 13, 2016 @water Oh ! EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
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