baghenamoth Posted November 21, 2007 Share Posted November 21, 2007 (edited) Hi here is my pb, I have to read some files. My script works well but when files are big (generally over 150 Mb, it depends of the computer/state of memory...) I got a message error : "Error allocating memory." and the script end I'd like to know if its possible to prevent this message box and simply handle error in my script so I could skip this file. $Result = Test("c:\mybigfile") ConsoleWrite($Result & @CR) Func Test($sFilePath) $hFile = FileOpen($sFilePath,16) If $hFile = -1 Then SetError(1) Return 0 EndIf $s_Line=FileRead($hFile,FileGetSize($sFilePath)) ; here is my error message "Error allocating memory." ; the scripts ends and console is AutoIT3.exe ended.rc:1 If @error = -1 Then ConsoleWrite("error detected" & @CR) FileClose($hFile) Return "error detected" EndIf FileClose($hFile) Return $s_Line EndFunc ;==>Test Edited November 21, 2007 by baghenamoth Link to comment Share on other sites More sharing options...
BrettF Posted November 21, 2007 Share Posted November 21, 2007 Hi here is my pb, I have to read some files. My script works well but when files are big (generally over 150 Mb, it depends of the computer/state of memory...) I got a message error : "Error allocating memory." and the script end I'd like to know if its possible to prevent this message box and simply handle error in my script so I could skip this file. $Result = Test("c:\mybigfile") ConsoleWrite($Result & @CR) Func Test($sFilePath) $hFile = FileOpen($sFilePath,16) If $hFile = -1 Then SetError(1) Return 0 EndIf $s_Line=FileRead($hFile,FileGetSize($sFilePath)) ; here is my error message "Error allocating memory." ; the scripts ends and console is AutoIT3.exe ended.rc:1 If @error = -1 Then ConsoleWrite("error detected" & @CR) FileClose($hFile) Return "error detected" EndIf FileClose($hFile) Return $s_Line EndFunc ;==>TestFileGetSize? Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
baghenamoth Posted November 21, 2007 Author Share Posted November 21, 2007 FileGetSize?sorry but I don't understand your answer.There is no pb with the FileGetSize Link to comment Share on other sites More sharing options...
zfisherdrums Posted November 21, 2007 Share Posted November 21, 2007 Hello baghenamoth, I believe what Bert is implying ( Bert: please correct me if I am wrong ) is that you should test the size of the file prior to opening it. If the file size is problematic for your environment, then do not open it. What I believe you are asking is if there is any structured error handling ( like "try...catch" blocks ) that can by employed in AutoIt scripts. I don't believe that functionality exists. Perhaps some industrious individuals on this forum have invented a way, but I have yet to see it. Have you been able to re-create this error on any other machines using the same files? Zach... Identify .NET controls by their design time namesLazyReader© could have read all this for you. Unit Testing for AutoItFolder WatcherWord Doc ComparisonThis here blog... Link to comment Share on other sites More sharing options...
baghenamoth Posted November 21, 2007 Author Share Posted November 21, 2007 Hello baghenamoth,I believe what Bert is implying ( Bert: please correct me if I am wrong ) is that you should test the size of the file prior to opening it. If the file size is problematic for your environment, then do not open it.yes i could do this but the size depends of the machine (cpu/memory...) and I need to open read and modify those files.What I believe you are asking is if there is any structured error handling ( like "try...catch" blocks ) that can by employed in AutoIt scripts. I don't believe that functionality exists. Perhaps some industrious individuals on this forum have invented a way, but I have yet to see it.this is exactly what I'me looking for..Have you been able to re-create this error on any other machines using the same files? Zach...oh yes, many many time ;-)anyway I found a solution :calling a first exe waiting for error message for each file (generally less than 100) calling a second exe which is going to open it, doing some stuff and returns ok if everithing is okwhen this second exe doesn't return ok I try an alternative : opening and reading the file line by line instead of opening it in one way yes it's a little bit "tiré par les cheveux" as we say in french, but it worksanyway, thx for your answers 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