Jump to content

FileExists() doesn't see files


Recommended Posts

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?

Link to comment
Share on other sites

  • Moderators

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

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
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 :)

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

ziuta1411,

Delighted to hear it.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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...