WhiskeyTangoFox

Issue with FileExists

6 posts in this topic

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.

#RequireAdmin
#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")
EndIf

; 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"
Else
    Global $CopyAppCheck = FileCopy("\\SomeDir\AppCheckx64.txt", "c:\Temp\AppCheckx64.txt")
    Global $AppCheck = "c:\Temp\AppCheckx64.txt"
EndIf

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)
    Exit
EndIf
If $rFileHandle = -1 Then
    MsgBox(0, "Post Image Test", "Failed to open " & $Results)
    Exit
EndIf

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

FileClose($aFileHandle)
FileClose($rFileHandle)
Run("notepad.exe " & $Results)

 

Share this post


Link to post
Share on other sites



@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

;Script
#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")
            Else
                MsgBox(0, "", "Nope")
            EndIf
    Next

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

@JLogan3o13 Thanks for the quick reply and test. Wonder if I'm picking up some erroneous characters from the text file. Attached is an example, fairly simple and straight forward. 

AppCheck.txt

Share this post


Link to post
Share on other sites

@WhiskeyTangoFox try removing the "" around the file paths in your text files.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

@JLogan3o13 That worked... I swear I'm losing my mind and had tried that... wow. Anyway, thank you very much for figuring that one out. I feel a little dense now, but at least I'm not at my wits end. If only everything were so simple, then again, were everything so simple I'd be out of an IT job. 

Share this post


Link to post
Share on other sites

Glad it worked for you :)


√-1 2^3 ∑ π, and it was delicious!

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