Sign in to follow this  
Followers 0
JSThePatriot

Unable to open file... maximum exceeded

24 posts in this topic

Here is the error...

>"C:\Program Files\AutoIt3\autoit3.exe" /ErrorStdOut "C:\Documents and Settings\JSThePatriot\My Documents\hrm.au3"   

C:\Documents and Settings\JSThePatriot\My Documents\hrm.au3 (12) : ==> Unable to open file, the maximum number of open files has been exceeded.:

$search = FileFindFirstFile($folder & $ext)

>Exit code: 0    Time: 0.519

And here is the code generating that error...

Dim $folder = "C:\PDF Files\";Folder to search for MemberID
Dim $ext = "*.*";Look for all files/folders
Dim $file2 = "unapw.txt";Username and Password File

$file = FileOpen($file2, 0)
If $file = -1 Then Exit

While 1
   $line = FileReadLine($file)
   If @error = -1 Then ExitLoop
   $array = StringSplit($line, "|")
   $search = FileFindFirstFile($folder & $ext)
   If $search = $array[1] Then
      $password = $array[2]
   Else
      Do
         $file = FileFindNextFile($search) 
         If @error Then ExitLoop
      Until $search = $array[1]
      If $search = $array[1] Then
         $password = $array[2]
      EndIf
   EndIf
WEnd

FileClose($search)

Any assistance would be greatly appreciated. I never knew there was a limit... I originally had this in another script, but I decided to pull it out and see if that was the problem, but still got the same error, not sure what I am doing wrong.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

FileFindFirstFile was changed to return a handle. The call to FileFindNextFile($handle) returns the filename. So the handle has to be closed with FileClose($handle).

I don't understand the usage of If $search = $array[1]

FileClose($search) needs to be before the WEnd

LAr

<{POST_SNAPBACK}>

I changed the code to look like this and it is processing all 13K records in that file... I will see what happens when it is done I suppose...

Dim $folder = "C:\PDF Files\";Folder to search for MemberID
Dim $ext = "*.*";Look for all files/folders
Dim $file2 = "unapw.txt";Username and Password File

$file = FileOpen($file2, 0)
If $file = -1 Then Exit

While 1
   $line = FileReadLine($file)
   If @error = -1 Then ExitLoop
   $array = StringSplit($line, "|")
   $search = FileFindFirstFile($folder & $ext)
   If $search = $array[1] Then
      $password = $array[2]
      MsgBox(0, "Success", "Whoo! MemberID: " & $array[1] & " Password: " & $password)
   Else
      Do
         $file = FileFindNextFile($search) 
         If @error Then ExitLoop
      Until $search = $array[1]
      If $search = $array[1] Then
         $password = $array[2]
         MsgBox(0, "Success", "Whoo! MemberID: " & $array[1] & " Password: " & $password)
      EndIf
   EndIf
   FileClose($search)
WEnd

FileClose($file)

BTW... the comparison is so that I can find the proper MemberID and match it up with the password.

Edit: 7 hours after I ran the program without any errors it still hasnt completed... I am guessing the logic is either running it in an endless loop, or it is just tooo slow this way and I will have to come at it from another angle.

JS

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

But what do you want to do?

What does $line contains?

What are looking for? Where are those MemberID?

Can you explain the problem in an other way again?

Share this post


Link to post
Share on other sites

You should read the stuff other members dedicate you

$search = FileFindFirstFile($folder & $ext)
...
If $search = $array[1] Then
...

As Larry told you, FileFindFirstFile($folder & $ext) returns a handle and I doubt that your 'unapw.txt' keeps different handles splitted by '|'

Rethink your code and use some ideas, that's the best way to get the things, better than getting a corrected code

Share this post


Link to post
Share on other sites

I explained the problem here... everyone seemed to forget about me so I went ahead and created my own search code after playing around with some stuff and reading some of the helpfile.

http://www.autoitscript.com/forum/index.php?showtopic=5430

Let me know if this isnt enough detail...

Thanks for looking,

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

You should read the stuff other members dedicate you

$search = FileFindFirstFile($folder & $ext)
...
If $search = $array[1] Then
...

As Larry told you, FileFindFirstFile($folder & $ext) returns a handle and I doubt that your 'unapw.txt' keeps different handles splitted by '|'

Rethink your code and use some ideas, that's the best way to get the things, better than getting a corrected code

<{POST_SNAPBACK}>

sPeziFisH I have already replied to Larry. I guess I didnt do it in enough detail as he just now posted this again. Maybe if you would give me a second to reply to him you wouldnt have to tell me I should.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

I still have a problem with this...

If $search = $array[1] Then

$search is a file handle. It has no relation to $array[1]

Lar.

<{POST_SNAPBACK}>

Ah but it does have a relation... as I will explain below.

If I put a message box outputing the $search function... it gives me file names and folder names. I am looking to match up the folder name (which equates to a memberID in the text file) then grab the password which is $array[2] and I can then use it to run my encryption program on all the files in that folder.

Thanks,

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

i don't believe you

<{POST_SNAPBACK}>

5 mins and I will give you print screen of it right out of the help file...

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Not sure I understand what you need, but this may help you.

Dim $sPassFile =  'c:\list.txt';Put the name of the pass file here.
If Not FileExists($sPassFile) Then Exit

Dim $ih, $c = 0, $aLine, $aIDPass[1][2], $aIDPassSize = 0
$aIDPass[0][0] = $aIDPassSize

$ih = FileOpen($sPassFile,0)
While 1
   $c = $c + 1
   $aLine = FileReadLine($ih,$c)
   If @error Then
      FileClose($ih)
      ExitLoop
   EndIf
   $aLine = StringSplit($aLine,'|')
   If Not @error Then
      $aIDPassSize = $aIDPassSize + 1
      ReDim $aIDPass[$aIDPassSize + 1][2]
      $aIDPass[$aIDPassSize][0] = $aLine[1]
      $aIDPass[$aIDPassSize][1] = $aLine[2]
      $aIDPass[0][0] = $aIDPassSize
   EndIf

Wend

For $c = 1 to $aIDPass[0][0]
 MsgBox(0,'',$aIDPass[$c][0] & '    ' &  $aIDPass[$c][1])
Next

This quick script will load c:\list.txt and separe the name and the passes and put them in the 2 dimensional array.

x > 0

$aIDPass[x][0] will contain the member IDs.

$aIDPass[x][1] will contain the passwords.

$aIDPass[0][0] will contain the number of elements.

$aIDPass[0][1] is unused.

Now... What do you want to do?

Sorry, for my poor english .

Edited by ezzetabi

Share this post


Link to post
Share on other sites

Here is how the help file put it... and the attachements show it.

Example

; Shows the filenames of all files in the current directory, note that "." and ".." are returned.

$search = FileFindFirstFile("*.*") 

; Check if the search was successful

If $search = -1 Then

    MsgBox(0, "Error", "No files/directories matched the search pattern")

    Exit

EndIf

While 1

    $file = FileFindNextFile($search)

    If @error Then ExitLoop

   

    MsgBox(4096, "File:", $file)

WEnd

; Close the search handle

FileClose($search)

I hope this explains for you Larry.. I may be doing it completely wrong, but it seemed logical to me....

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

JSThePatriot, I guess you want to do sth. that:

For $c = 1 to $aIDPass[0][0]
    RunWait(@ComSpec & " /c " & "...program to run..." & "c:\PDF\" & $aIDPass[$c][0] & "\*.pdf" & " ..." , "", @SW_HIDE)
Next

use $aIDPass[x][1] as encryption-passwd within the program-call (means: use it as part of the commandline)

- Larry and me posted at the same time :)

- ur MsgBox shows $file and not $search as you told before

Share this post


Link to post
Share on other sites

Not sure I understand what you need, but this may help you.

Dim $sPassFile =  'c:\list.txt';Put the name of the pass file here.
If Not FileExists($sPassFile) Then Exit

Dim $ih, $c = 0, $aLine, $aIDPass[1][2], $aIDPassSize = 0
$aIDPass[0][0] = $aIDPassSize

$ih = FileOpen($sPassFile,0)
While 1
   $c = $c + 1
   $aLine = FileReadLine($ih,$c)
   If @error Then
      FileClose($ih)
      ExitLoop
   EndIf
   $aLine = StringSplit($aLine,'|')
   If Not @error Then
      $aIDPassSize = $aIDPassSize + 1
      ReDim $aIDPass[$aIDPassSize + 1][2]
      $aIDPass[$aIDPassSize][0] = $aLine[1]
      $aIDPass[$aIDPassSize][1] = $aLine[2]
      $aIDPass[0][0] = $aIDPassSize
   EndIf

Wend

For $c = 1 to $aIDPass[0][0]
 MsgBox(0,'',$aIDPass[$c][0] & '    ' &  $aIDPass[$c][1])
Next

This quick script will load c:\list.txt and separe the name and the passes and put them in the 2 dimensional array.

x > 0

$aIDPass[x][0] will contain the member IDs.

$aIDPass[x][1] will contain the passwords.

$aIDPass[0][0] will contain the number of elements.

$aIDPass[0][1] is unused.

Now... What do you want to do?

Sorry, for my poor english .

<{POST_SNAPBACK}>

Hrm... I am not sure exactly what that does... I just need it to search through my directory C:\PDF Files\ and find folders with the same name as a part of a line in the unapw.txt file.

So... it finds a folder with C:\PDF Files\14 I want it to then look in my unapw.txt file and find the line that contains 14|passhere. It then puts that password into the $password variable. I need it to do that for all the folders in C:\PDF Files\.

Understand?

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Reading and re reading I think I solved your problem.

Dim $sPassFile =  'c:\list.txt';Put the name of the pass file here.
If Not FileExists($sPassFile) Then Exit
Dim $sFolder = 'c:\';Put here where you want to seek your your member ID folders. WITH TRAILING BACKSLASH

Dim $ih, $c = 0, $aLine, $aIDPass[1][3], $aIDPassSize = 0, $aSearchResult
$aIDPass[0][0] = $aIDPassSize

$ih = FileOpen($sPassFile,0)
While 1
   $c = $c + 1
   $aLine = FileReadLine($ih,$c)
   If @error Then
      FileClose($ih)
      ExitLoop
   EndIf
   $aLine = StringSplit($aLine,'|')
   If Not @error Then
      $aIDPassSize = $aIDPassSize + 1
      ReDim $aIDPass[$aIDPassSize + 1][2]
      $aIDPass[$aIDPassSize][0] = $aLine[1]
      $aIDPass[$aIDPassSize][1] = $aLine[2]
      $aIDPass[0][0] = $aIDPassSize
      $aSearchResult = _FileSearch($sFolder & $aIDPass[$aIDPassSize][0],1)
      If $aSearchResult[0] > 0 Then
         $aIDPass[$aIDPassSize][3] = $aSearchResult[1];<- Assuming that the first folder found is the right one.
      Else
         $aIDPass[$aIDPassSize][3] = 'No folder for this member ID'
      EndIf
   EndIf

Wend

For $c = 1 to $aIDPass[0][0]
MsgBox(0,'',$aIDPass[$c][0] & @lf &  $aIDPass[$c][1] & @lf & $aIDPass[$c][2])
Next

You need the _FileSearch func I made (or the Larry one of course).

At the end this script should give you a two dimensional array with

x > 0

$aIDPass[x][0] will contain the member IDs.

$aIDPass[x][1] will contain the passwords.

$aIDPass[x][2] will contain the member ID folder.

$aIDPass[0][0] will contain the number of elements.

$aIDPass[0][1] and $aIDPass[0][2] are unused.

Ok. Thats it... If you have still problems, ask again.

Edit: What in the hell happened here? Wow.

Edit (2): Corrected $aIDPass[$aIDPassSize][3] = $aSearchResult[1] Line. We have to take the first result, not the number of them... :)

Edited by ezzetabi

Share this post


Link to post
Share on other sites

JSThePatriot, I guess you want to do sth. that:

For $c = 1 to $aIDPass[0][0]
    RunWait(@ComSpec & " /c " & "...program to run..." & "c:\PDF\" & $aIDPass[$c][0] & "\*.pdf" & " ..." , "", @SW_HIDE)
Next

use $aIDPass[x][1] as encryption-passwd within the program-call (means: use it as part of the commandline)

- Larry and me posted at the same time  :)

- ur MsgBox shows $file and not $search as you told before

<{POST_SNAPBACK}>

Ah you are correct.. Yes you did post at the same time... sorry for snapping.. it just seemed you were just jumping on me when I hadnt even read the post yet and I thought I had answered it before. Okay so the $file is what I am missing... or messed up on.. thanks for pointing out my error. I knew something had to be wrong. Yea I already have my code to do the whole encryption thing. I still dont understand how that finds the directory I need and then also lines it up with a password in my file.

JS

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

Reading and re reading I think I solved your problem.

Dim $sPassFile =  'c:\list.txt';Put the name of the pass file here.
If Not FileExists($sPassFile) Then Exit
Dim $sFolder = 'c:\';Put here where you want to seek your your member ID folders. WITH TRAILING BACKSLASH

Dim $ih, $c = 0, $aLine, $aIDPass[1][3], $aIDPassSize = 0, $aSearchResult
$aIDPass[0][0] = $aIDPassSize

$ih = FileOpen($sPassFile,0)
While 1
   $c = $c + 1
   $aLine = FileReadLine($ih,$c)
   If @error Then
      FileClose($ih)
      ExitLoop
   EndIf
   $aLine = StringSplit($aLine,'|')
   If Not @error Then
      $aIDPassSize = $aIDPassSize + 1
      ReDim $aIDPass[$aIDPassSize + 1][2]
      $aIDPass[$aIDPassSize][0] = $aLine[1]
      $aIDPass[$aIDPassSize][1] = $aLine[2]
      $aIDPass[0][0] = $aIDPassSize
      $aSearchResult = _FileSearch($sFolder & $aIDPass[$aIDPassSize][0],1)
      If $aSearchResult[0] > 0 Then
         $aIDPass[$aIDPassSize][3] = $aSearchResult[0];<- Assuming that the first folder found is the right one.
      Else
         $aIDPass[$aIDPassSize][3] = 'No folder for this member ID'
      EndIf
   EndIf

Wend

For $c = 1 to $aIDPass[0][0]
MsgBox(0,'',$aIDPass[$c][0] & @lf &  $aIDPass[$c][1] & @lf & $aIDPass[$c][2])
Next

You need the _FileSearch func I made (or the Larry one of course).

At the end this script should give you a two dimensional array with

x > 0

$aIDPass[x][0] will contain the member IDs.

$aIDPass[x][1] will contain the passwords.

$aIDPass[x][2] will contain the member ID folder.

$aIDPass[0][0] will contain the number of elements.

$aIDPass[0][1] and $aIDPass[0][2] are unused.

Ok. Thats it... If you have still problems, ask again.

Edit: What in the hell happened here? Wow.

<{POST_SNAPBACK}>

I will give that a shot after I get back from lunch! Thank you so much for getting that together for me...

I dont quite understand everything it is doing yet, but I will do my best.

I am going to post the code I just fixed and see if you guys can tell me why it wouldnt work (it is far fewer lines).

$file = FileOpen($file2, 0)
If $file = -1 Then Exit

While 1
   $line = FileReadLine($file)
   If @error = -1 Then ExitLoop
   $array = StringSplit($line, "|")
   $search = FileFindFirstFile($folder & $ext)
   Do
      $file3 = FileFindNextFile($search) 
      If @error Then ExitLoop
   Until $file3 = $array[1]
   If $file3 = $array[1] Then
      $password = $array[2]
   EndIf
   FileClose($file3)
   FileClose($search)
WEnd

FileClose($file)

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

OK, you have frustrated me enough to help... $search is a file handle and does you NO good in a text comparison... You used $file twice... as a handle and a return from FileFindNextFile...

Dim $folder = "C:\PDF Files\";Folder to search for MemberID
Dim $ext = "*.*";Look for all files/folders
Dim $file2 = "unapw.txt";Username and Password File

$file = FileOpen($file2, 0)
If $file = -1 Then Exit

While 1
  $line = FileReadLine($file)
  If @error Then ExitLoop
  $array = StringSplit($line, "|")
  $search = FileFindFirstFile($folder & $ext)
  If $search <> -1 Then
     While 1
        $filestring = FileFindNextFile($search) 
        If @error Then ExitLoop
        If StringInStr($filestring,$array[1]) Then
           $password = $array[2]
           MsgBox(0, "Success", "MemberID: " & $array[1] & @LF & _
              "Password: " & $password & @LF & "FileName: " & $filestring)
        EndIf
    WEnd
    FileClose($search)
  EndIf
WEnd
FileClose($file)

I think that will work, however... I am sure there is another way... I just odified your code...

Lar.

<{POST_SNAPBACK}>

I am sorry to have frustrated you Larry :) not my intention at all :) .

I just changed my code... to say file3 instead of using file again... I didnt notice that until I was reviewing it again. I didnt see the $search thing until it was pointed out in here. I was wrong there to. Thank you for the help I do appreciate it.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

Have you considered FileExists with wildcards?

If FileExists("*" & $array[1] & "*.pdf")

Lar.

<{POST_SNAPBACK}>

Does FileExists() allow for finding folders? I know the files will be there... I just need to know if the folders are there... that is why I was using the function I was using... Your function seems to work needs to be optimized so it doesnt find everything with a 4 or a 5 in it...

I will work on it when I get back from lunch.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

Larry here is how I modified what you modified for me so the results work :)

Dim $folder = "C:\PDF Files\";Folder to search for MemberID
Dim $ext = "*.*";Look for all files/folders
Dim $file2 = "unapw.txt";Username and Password File

$file = FileOpen($file2, 0)
If $file = -1 Then Exit

While 1
 $line = FileReadLine($file)
 If @error Then ExitLoop
 $array = StringSplit($line, "|")
 $search = FileFindFirstFile($folder & $ext)
 If $search <> -1 Then
    While 1
       $filestring = FileFindNextFile($search)
       If @error Then ExitLoop
       If $filestring = $array[1] Then
          $password = $array[2]
          MsgBox(0, "Success", "MemberID: " & $array[1] & @LF & _
             "Password: " & $password & @LF & "FileName: " & $filestring)
       EndIf
   WEnd
   FileClose($search)
 EndIf
WEnd
FileClose($file)

JS

P.S. Thank you soo much for your help and patience. I am sorry I irritated you :).


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

JSThePatriot (Or anybody else), in the future, if Larry says something, do it, don't ask why, just do it. 99% chance it will work.

Share this post


Link to post
Share on other sites

JSThePatriot (Or anybody else), in the future, if Larry says something, do it, don't ask why, just do it.  99% chance it will work.

<{POST_SNAPBACK}>

This is true, but if I would have done that would I have learned? I thought you guys were all about us learning... also if I would have done that my code would be well over a hundred lines long.

I do respect Larry's coding ability, as I do yours, but I do not just do things without question.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
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
Sign in to follow this  
Followers 0