Jump to content

Recommended Posts

Posted

I'm having a very frustrating time with this one. The function seemed to work just fine for a little while but now it doesn't. If I run it like this

Local $fileCheck = FileFindFirstFile (@ScriptDir & "886*dat.exe")
        MsgBox (0, "", $fileCheck)

it pops up with a -1 which the help file indicates means it didn't find a file matching the specifications. If I change it to this

Local $fileCheck = FileFindFirstFile (@ScriptDir & "\886*dat.exe")
        MsgBox (0, "", $fileCheck)

it throws a 1 which the help file indicates means the directory is empty. I have quadruple (or more) checked the folder...the file I want it to find is in the directory. If I have a box generated to indicate the @ScriptDir, it gives me the proper path (the folder where this file is located). This happens even if I narrow down the argument to

Local $fileCheck = FileFindFirstFile (@ScriptDir & "*dat.exe")
        MsgBox (0, "", $fileCheck)

I could have sworn this worked exactly the way I wanted it to at least 3 times during testing. I was working on using the same code snippet/concept to provide additional functionality and I was having a hard time with it so I checked this one and it wasn't working now either. I'm totally stumped and I have gone as thoroughly through the help file on the particular function to no avail. I have multiple includes in my file

; *** Start added by AutoIt3Wrapper ***
#include <AutoItConstants.au3>
; *** End added by AutoIt3Wrapper ***
#NoTrayIcon
;~ #RequireAdmin
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <Inet.au3>
#include <Constants.au3>
#include <Process.au3>
#include <WinAPIShPath.au3>
#include <Array.au3>
#include <IE.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>

so I don't think I'm missing to make this function work. If needed, I can post the entire code, so let me know.

Posted (edited)

Post the whole script. Are you using FileClose appropriately? It returns a HANDLE To be used with the rest of the fle functions.

@error which you are not checking is set to 1 if the folder is empty. It may be working. Use the handle to do something. Try FileReadLine using the handle returned from FindFirstFile after making sure you run as admin and @error is 0

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted

"it throws a 1 which the help file indicates means the directory is empty. " as Earthshine mentioned, this actually indicates that the file was found.  You can use something similar to  the following to check the status:

Example()

Func Example()
    Local $sFileName
    Local $hFileCheck = FileFindFirstFile (@ScriptDir & "\886*dat.exe")
    If @error = 1 Then
        MsgBox(16, "", "Error: Directories is empty.")
    ElseIf $hFileCheck = - 1 Then
        MsgBox(16, "", "Error: No files/directories matched the search pattern.")
        Return False
    EndIf
    While 1
        $sFileName = FileFindNextFile($hFileCheck)
        If @error Then ExitLoop
        $iMsgBox = MsgBox(4097, "", "File: " & $sFileName)
        If $iMsgBox <> 0 Then ExitLoop
    WEnd
    FileClose($hFileCheck)
EndFunc

 

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
  • Recently Browsing   0 members

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