ziuta1411 Posted October 7, 2015 Posted October 7, 2015 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 ) EndIfNextOnly 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?
Moderators Melba23 Posted October 7, 2015 Moderators Posted October 7, 2015 ziuta1411,Welcome to the AutoIt forums.Some suggestions:Use a For...To...Next loop to work through the arrayCheck the paths are full and not relativeAnd 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
computergroove Posted October 7, 2015 Posted October 7, 2015 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
ziuta1411 Posted October 8, 2015 Author Posted October 8, 2015 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\TESTd:\AutoIt\TEST\test1.txtd:\AutoIt\TEST\test1.batand 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
Moderators Melba23 Posted October 8, 2015 Moderators Posted October 8, 2015 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
ziuta1411 Posted October 12, 2015 Author Posted October 12, 2015 Thank You, it works I don't really know why, but it solves the problem
Moderators Melba23 Posted October 12, 2015 Moderators Posted October 12, 2015 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now