Jump to content

file handle error


masvil
 Share

Recommended Posts

Hi,

My piece of code:

--begine--

If FileExists(@ScriptDir & "\*.exe") Then

$search = FileFindFirstFile("*.exe")

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

RunWait($file)

Wend

FileClose($search)

EndIf

--end--

There are a lot of file handle loop like this in my script.

This is error that sometimes I get:

--begin--

Line 0 (File "..."):

$file = FileFindNextFile($search)

Error: File handle invalid. Make sure that the FileOpen command succeeded

--end--

I can't explain why it talk about "FileOpen": what and why I have to open a file?

Help say just to FileClose at the end of file handle!

--

MasviL

Link to comment
Share on other sites

I think I might know the problem:

You never check the return value of FileFindFirstFile, so it's possible that it fails and returns -1. For me, calling FileFindNextFile(-1) results in an error message "Invalid file handle used," but I'm using the latest beta of version of AutoIt.

You might think that the "If FileExists(@ScriptDir & "\*.exe") Then" should guarantee that the FileFindFirstFile should always succeed, but it *might* be looking in a different folder. If the current active "working" folder is C:\Windows\Temp, then that's where FileFindFirstFile is going to look.

You might try calling the FileChangeDir function before your code sample, or you could explicitly call FileFindFirstFile(@ScriptDir & "\*.exe") if that's what you intend.

Hope this helps

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...