smellystudent Posted May 23, 2006 Share Posted May 23, 2006 I'm having trouble with one of my scripts. I'm hitting the open file limit, but I'm unable to see what I'm doing wrong. The relevant bit of the script is: $search = FileFindFirstFile("search_mdetails.asp*.*") If $search = -1 Then MsgBox(0, "Error", "No files in directory") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileOpen($file,0) $filecontents = FileRead($file) FileClose($file) <<do stuff with $filecontents>> $output = FileOpen("output.csv",1) FileWrite($output,$stuff) FileClose($output) WEnd FileClose($search) What have I missed? Link to comment Share on other sites More sharing options...
HardCopy Posted May 23, 2006 Share Posted May 23, 2006 Your Posted code seems to be ok, the problem would appear to be where you are processing the $filecontents, post that section and may be able to help further. HardCopy Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad Link to comment Share on other sites More sharing options...
Thatsgreat2345 Posted May 23, 2006 Share Posted May 23, 2006 now what i see is your searching for $search = FileFindFirstFile("search_mdetails.asp*.*") but does .asp really have any other extension on the end? Link to comment Share on other sites More sharing options...
smellystudent Posted May 23, 2006 Author Share Posted May 23, 2006 Your Posted code seems to be ok, the problem would appear to be where you are processing the $filecontents, post that section and may be able to help further. HardCopy If you really want it $pos = StringInStr($filecontents,"<big>",0,2) $filecontents = StringTrimLeft ($filecontents, $pos+4) $pos = StringInStr($filecontents,"</big>",0,1) $company = StringLeft ($filecontents, $pos-1) $filecontents = StringTrimLeft ($filecontents, $pos) $pos = StringInStr($filecontents,"Address</td>",0,1) $filecontents = StringTrimLeft ($filecontents, $pos+57) $pos = StringInStr($filecontents,"<br>",0,1) $address1 = StringLeft ($filecontents, $pos-1) $filecontents = StringTrimLeft ($filecontents, $pos+3) $pos = StringInStr($filecontents,"<br>",0,1) $address2 = StringLeft ($filecontents, $pos-1) $filecontents = StringTrimLeft ($filecontents, $pos+3) $pos = StringInStr($filecontents,"</td>",0,1) $postcode = StringLeft ($filecontents, $pos-1) $filecontents = StringTrimLeft ($filecontents, $pos+4) $pos = StringInStr($filecontents,"Telephone</td>",0,1) $filecontents = StringTrimLeft ($filecontents, $pos+59) $pos = StringInStr($filecontents,"</td>",0,1) $phone = StringLeft ($filecontents, $pos-1) $filecontents = StringTrimLeft ($filecontents, $pos+4) I don't think there's anything in there trying to open files. Link to comment Share on other sites More sharing options...
smellystudent Posted May 23, 2006 Author Share Posted May 23, 2006 now what i see is your searching for $search = FileFindFirstFile("search_mdetails.asp*.*") but does .asp really have any other extension on the end? The files are all in the form "search_mdetails.asp&id=0123456789ABCDEF.htm". You're right that the second wildcard isn't actually necessary, but removing it sadly doesn't afffect the files-open error Link to comment Share on other sites More sharing options...
HardCopy Posted May 23, 2006 Share Posted May 23, 2006 I don't think there's anything in there trying to open files.Indeed Well using your original code, with the necessary changes - i read 10k+ image filesin a single directoryread the filewrote the filename to an output filewith no errors.Maybe someone else can see the problem, You got me stumped!HardCopy Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad Link to comment Share on other sites More sharing options...
ChrisL Posted May 23, 2006 Share Posted May 23, 2006 Are you using the latest beta? If not download it and try it I'm having trouble with one of my scripts. I'm hitting the open file limit, but I'm unable to see what I'm doing wrong. The relevant bit of the script is: $search = FileFindFirstFile("search_mdetails.asp*.*") If $search = -1 Then MsgBox(0, "Error", "No files in directory") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop FileOpen($file,0) $filecontents = FileRead($file) FileClose($file) <<do stuff with $filecontents>> $output = FileOpen("output.csv",1) FileWrite($output,$stuff) FileClose($output) WEnd FileClose($search) What have I missed? [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 Link to comment Share on other sites More sharing options...
smellystudent Posted May 23, 2006 Author Share Posted May 23, 2006 Are you using the latest beta?If not download it and try itAlready have I'm afraid Link to comment Share on other sites More sharing options...
Don N Posted May 23, 2006 Share Posted May 23, 2006 could you post the exact error message here. ur code seems fine, i also ran it with some modifications on a folder of over 5000 log files and it worked fine. _____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper Link to comment Share on other sites More sharing options...
Don N Posted May 23, 2006 Share Posted May 23, 2006 In the loop tho wouldnt that handle be the same as the one returned from FileFindNextFile() because they are both using the same file? Would FileOpen() make another instance of that file handle that also needs to be closed? Would this work or would you still need to close 2 file handes since 2 are returned from the functions? $file = FileOpen( FileFindNextFile($search), 0 ) If @error Then ExitLoop $filecontents = FileRead($file) FileClose($file) _____________________________________________________"some people live for the rules, I live for exceptions"Wallpaper Changer - Easily Change Your Windows Wallpaper Link to comment Share on other sites More sharing options...
smellystudent Posted May 23, 2006 Author Share Posted May 23, 2006 FileOpen() returns a handle (which you do not record) that needs to be closed. at the end you use FileOpen correctly... in the loop you do not. Bingo! Thank you Larry. Corrected code, for reference: *snip* $file = FileFindNextFile($search) If @error Then ExitLoop $filehandle = FileOpen($file,0) $filecontents = FileRead($file) FileClose($filehandle) *snip* Link to comment Share on other sites More sharing options...
HardCopy Posted May 23, 2006 Share Posted May 23, 2006 Bingo! Thank you Larry.Hmm, After chopping down some trees & seeing wood, makes sense now.But, now im stumped why my trials didn't emulate smelly's error also.HardCopy Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad 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