ziuta1411

FileExists() doesn't see files

7 posts in this topic

Hi,

I have a problem with using FileExists(). I have an array which contains few paths. I try to check if those paths are created by using following code:

For $item in $aPATHS
  If FileExists($item) == 1 Then
      FileWrite($hLogOpen, $item & ' exists' & @CRLF)
   Else
      FileWrite($hLogOpen,$item & ' does not exists' & @CRLF )
   EndIf
Next

Only with first path I get expected outcom, in every other case FileExists returns 0, despite the fact that file actually exists. I'll be grateful for some pointers - what am I doing wrong?

Share this post


Link to post
Share on other sites



ziuta1411,

Welcome to the AutoIt forums.

Some suggestions:

  • Use a For...To...Next loop to work through the array
  • Check the paths are full and not relative

And you should use the "=" operator to do the comparison ("==" forces a case-sensitive string comparison), although in this case it should not make a difference.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

messagebox the $item in the loop to see exactly what is being seen by autoit to search for. Is it exactly what is in your array? Are any of these paths in Program Files?


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

Thank You for your reply :) I used your advice and came up with:

For $i = 0 To UBound($aPATHS) - 1
  Global $tmp = $aPATHS[$i]
  If FileExists($tmp) = 1 Then
      FileWrite($hLogOpen, $tmp & 'exists' & @CRLF)
   Else
      FileWrite($hLogOpen, $tmp & 'does not exists' & @CRLF)
   EndIf
 Next

$aPATHS array is loaded from a text file, that contains paths like:

d:\AutoIt\TEST

d:\AutoIt\TEST\test1.txt

d:\AutoIt\TEST\test1.bat

and few more, all of these files are in d:\AutoIt\TEST directory, which is the only path that FileExists() sees. None of them are in Program Files. I've displayed $tmp in messagebox and it shows exactly the same string that is in a file.....

And it still doesn't work... Is there any function, that can substitute for FileExists() ?  Maybe it's a newbie question, but I've only been trying autoit for 3 days :)

Share this post


Link to post
Share on other sites

ziuta1411,

I have just run your code (with a few added lines) and it works perfectly for me:

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

; Read path file into an array

Global $aPATHS

_FileReadToArray("Paths.txt", $aPATHS, $FRTA_NOCOUNT)

; Create log file
$sLogfile = "Log.txt"
$hLogOpen = FileOpen($sLogFile, $FO_OVERWRITE)

; Loop through array
For $i = 0 To UBound($aPATHS) - 1
  Global $tmp = $aPATHS[$i]
  If FileExists($tmp) = 1 Then
      ConsoleWrite($tmp & " found" & @CRLF)
      FileWrite($hLogOpen, $tmp & ' exists' & @CRLF)
  Else
      ConsoleWrite($tmp & " NOT found" & @CRLF)
      FileWrite($hLogOpen, $tmp & ' does not exists' & @CRLF)
   EndIf

Next

; Close log file
FileClose($hLogOpen)

; Read the content
$sContent = FileRead($sLogFile)
MsgBox($MB_SYSTEMMODAL, "Result", $sContent)

; Delete log file
FileDelete($sLogFile)

Try running that on your path list.

If it does not work, then please post the file which holds the paths - I am wondering if there s not a problem with its internal structure that prevents you reading more than the first entry.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

Share this post


Link to post
Share on other sites

Thank You, it works :) I don't really know why, but it solves the problem :)

Share this post


Link to post
Share on other sites

ziuta1411,

Delighted to hear it.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

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