Jump to content

Recommended Posts

Howdy All, fairly new to Autoit, running into an issue with FileExists always returning negative results. I'm reading a list of files with the full directory path from a text file into an array, directories are double quoted (have tried single and no quotes, as well as adding quotes after the fact). Then cycling through the array I'm checking to see if the files in question exist and reporting back the results. Regardless of the file existing I get back negative results. I've checked the array, it has the proper values. I've checked the value passed to FileExists, it looks correct. To try to rule out permissions issue, I've run as Admin, logging in as an admin and executing, including #RequireAdmin, everything returns the same results... 

If I hard code the directory in it works fine so it's not a permissions issue. There's something with reading the directory from an array or even doing a FileReadLine that results in negative results. I'm completely stumped... Am I missing something obvious? 

For reference, the entries in the AppCheck.txt and AppCheckx64.txt files that I'm reading from would look something like: 

"C:\Program Files\Windows Media Player\wmplayer.exe"

With a new entry/value on each line.

#include <File.au3>
#include <FileConstants.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>

Global $WriteResults, $line, $iFileExists, $I, $LineArray
Global $CreateResults = _FileCreate("c:\Temp\Results.txt")
If @error = 1 Then
    MsgBox(0, "Post Image Test", "There was an error creating a results file in C:\Temp")
ElseIf @error = 2 Then
    MsgBox(0, "Post Image Test", "The results file could not be written to")

; Check for OS type and pull down corresponding list of apps to check
If @OSArch = "X86" Then
    Global $CopyAppCheck = FileCopy("\\SomeDir\AppCheck.txt", "c:\Temp\AppCheck.txt")
    Global $AppCheck = "c:\Temp\AppCheck.txt"
    Global $CopyAppCheck = FileCopy("\\SomeDir\AppCheckx64.txt", "c:\Temp\AppCheckx64.txt")
    Global $AppCheck = "c:\Temp\AppCheckx64.txt"

Global $Results = "c:\Temp\Results.txt"
Global $aFileHandle = FileOpen($AppCheck, 0)
Global $rFileHandle = FileOpen($Results, 10)
If $aFileHandle = -1 Then
    MsgBox(0, "Post Image Test", "Failed to open " & $AppCheck)
If $rFileHandle = -1 Then
    MsgBox(0, "Post Image Test", "Failed to open " & $Results)

_FileReadToArray($AppCheck, $LineArray)
For $I = 1 to $LineArray[0]
    $iFileExists = FileExists($LineArray[$I])
    If $iFileExists Then
        $WriteResults = FileWriteLine($rFileHandle, "OK - " & $LineArray[$I])
        $WriteResults = FileWriteLine($rFileHandle, "FAILED - " & $LineArray[$I])

Run("notepad.exe " & $Results)


Link to post
Share on other sites
  • Moderators

@WhiskeyTangoFox welcome to the forum. Could you post an example of your AppCheck text files? A shortened version of your filereadtoarray (below) works for me. I am curious about the format of the files you're using.

;format in my files.txt file - C:\Program Files\Windows Media Player\wmplayer.exe

#include <File.au3>
#include <Array.au3>
Local $LineArray
    _FileReadToArray(@DesktopDir & "\files.txt", $LineArray)

    For $i = 1 to $LineArray[0]
        $iFileExists = FileExists($LineArray[$i])
            If $iFileExists Then
                MsgBox(0, "", "Yup")
                MsgBox(0, "", "Nope")


"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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

    No registered users viewing this page.

  • Create New...