Megaben3 Posted December 19, 2021 Posted December 19, 2021 Hello, Have a strange problem! Readline from config.txt file and put string to variable Use this string with FileExist ( = no exist ) If I set the same variable with the same string, FileExist (= exist) The difference, is the string source ! Sample code: #include <Array.au3> #include <String.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> Global $sConfigPath = (@ScriptDir & "\Config.txt") Func GetConfigFile() Global $sConfigOpen = FileOpen ($sConfigPath, $FO_READ) If $sConfigOpen = -1 Then; if open error MsgBox($MB_SYSTEMMODAL, "", "error reading Config.txt.") Exit EndIf For $nLine = 1 to 3 Global $sReadConfig = FileReadLine ($sConfigOpen,$nLine) If $nLine = 1 then Global $sDownloadFolderPath = $sReadConfig If $nLine = 2 then Global $sLocalFolderPath = $sReadConfig If $nLine = 3 then Global $sTabloFolderPath = $sReadConfig; the value is good "D:\Media\Tablo\" ;Global $sTabloFolderPath = "Global $sTabloFolderPath = "D:\Media\Tablo\"; if I set this, Tablo exist = YES CheckIfTabloExist() ; result is NO, this path exist, no understand because ? Next EndFunc Func CheckIfTabloExist() IF FileExists($sTabloFolderPath) Then Global $sTabloExist = "YES" Else Global $sTabloExist = "NO" Beep (800, 1000) MsgBox($MB_SYSTEMMODAL, "", "TabloExist = : " & $sTabloExist) Exit EndIf EndFunc Thank you for your help! Megaben3
water Posted December 19, 2021 Posted December 19, 2021 Because you call CheckIfTabloExist 3 times. Only on the third call sTabloFolderPath exists and has valid content. I would modify your script as follows: #include <Array.au3> #include <String.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> Global $hConfigOpen, $sReadConfig, $sDownloadFolderPath, $sLocalFolderPath, $sTabloFolderPath Global $sConfigPath = (@ScriptDir & "\Config.txt") Func GetConfigFile() $hConfigOpen = FileOpen($sConfigPath, $FO_READ) If $hConfigOpen = -1 Then Exit MsgBox($MB_SYSTEMMODAL, "", "error reading Config.txt.") ; If open error For $nLine = 1 To 3 $sReadConfig = FileReadLine($hConfigOpen, $nLine) If $nLine = 1 Then $sDownloadFolderPath = $sReadConfig If $nLine = 2 Then $sLocalFolderPath = $sReadConfig If $nLine = 3 Then $sTabloFolderPath = $sReadConfig If Not FileExists($sTabloFolderPath) Then Beep(800, 1000) MsgBox($MB_SYSTEMMODAL, "", $sTabloFolderPath & " does not exist!") Exit EndiF Endif Next EndFunc ;==>GetConfigFile Megaben3 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Danp2 Posted December 19, 2021 Posted December 19, 2021 I would suggest changing several things -- Move your Global declarations outside of the functions Move the call to CheckIfTabloExist outside of your For...Next. Otherwise, you call it multiple times when the value hasn't been set. You may want to look at using FileReadToArray, which would allow you to do something like this -- Local $aFiles = FileReadToArray($sConfigPath) $sDownloadFolderPath = $aFiles[0] $sLocalFolderPath = $aFiles[1] $sTabloFolderPath = $aFiles[2] Megaben3 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
Developers Jos Posted December 19, 2021 Developers Posted December 19, 2021 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team Megaben3 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
ad777 Posted December 19, 2021 Posted December 19, 2021 (edited) Remove Exit Function it will exit the loop see.https://www.autoitscript.com/autoit3/docs/keywords/Exit.htm Edited December 19, 2021 by ad777 Megaben3 1 none
Megaben3 Posted December 19, 2021 Author Posted December 19, 2021 Hello, Have tested the water script, have the same problem, the path does not exist! Try Danp2 Array script and come back with result. May be is Windows x64 vs script 32bits ? Thank you for your fast answers Megaben3
Danp2 Posted December 19, 2021 Posted December 19, 2021 14 minutes ago, Megaben3 said: Have tested the water script, have the same problem, the path does not exist! Did you add a line that calls GetConfigFile? If not, then then function never gets called. Latest Webdriver UDF Release Webdriver Wiki FAQs
Megaben3 Posted December 20, 2021 Author Posted December 20, 2021 Hello Danp2, Your array method is the best, I love it ! Have the same problem. Complete revised code : #include <Array.au3> #include <String.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> Global $hConfigOpen, $sReadConfig, $sDownloadFolderPath, $sLocalFolderPath, $sTabloFolderPath, $sTabloExist Global $sConfigPath = (@ScriptDir & "\Config.txt") Global $aFiles = FileReadToArray($sConfigPath) Call ("GetConfigFile") Func GetConfigFile() $hConfigOpen = FileOpen($sConfigPath, $FO_READ) If $hConfigOpen = -1 Then Exit MsgBox($MB_SYSTEMMODAL, "", "error reading Config.txt.") ; If open error $sDownloadFolderPath = $aFiles[0] $sLocalFolderPath = $aFiles[1] $sTabloFolderPath = $aFiles[2] If Not FileExists($sTabloFolderPath) Then Beep(800, 1000) MsgBox($MB_SYSTEMMODAL, "", $sTabloFolderPath & " does not exist!"); always not exist EndiF MsgBox($MB_SYSTEMMODAL, "", $sTabloFolderPath); display good path EndFunc ;==>GetConfigFile config - array.au3 Config.txt
Megaben3 Posted December 20, 2021 Author Posted December 20, 2021 Hello, Have find how display code in forum #include <Array.au3> #include <String.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> Global $hConfigOpen, $sReadConfig, $sDownloadFolderPath, $sLocalFolderPath, $sTabloFolderPath, $sTabloExist Global $sConfigPath = (@ScriptDir & "\Config.txt") Global $aFiles = FileReadToArray($sConfigPath) Call ("GetConfigFile") Func GetConfigFile() $hConfigOpen = FileOpen($sConfigPath, $FO_READ) If $hConfigOpen = -1 Then Exit MsgBox($MB_SYSTEMMODAL, "", "error reading Config.txt.");If open error $sDownloadFolderPath = $aFiles[0] $sLocalFolderPath = $aFiles[1] $sTabloFolderPath = $aFiles[2] If Not FileExists($sTabloFolderPath) Then Beep(800, 1000) MsgBox($MB_SYSTEMMODAL, "", $sTabloFolderPath & " does not exist!");always not exist EndiF MsgBox($MB_SYSTEMMODAL, "", $sTabloFolderPath);display good path EndFunc ;==>GetConfigFile
Solution Danp2 Posted December 20, 2021 Solution Posted December 20, 2021 It's possible that the quotation marks are causing the issue. Have you tried removing them from the 3rd line? P.S. You don't need these lines in your function as the contents have already been read into an array -- $hConfigOpen = FileOpen($sConfigPath, $FO_READ) If $hConfigOpen = -1 Then Exit MsgBox($MB_SYSTEMMODAL, "", "error reading Config.txt.");If open error Megaben3 1 Latest Webdriver UDF Release Webdriver Wiki FAQs
Megaben3 Posted December 20, 2021 Author Posted December 20, 2021 Hello Danp2, You have found the solution. Have remove quotation marks from path. It's work great ! With your array method, not need open and close file, wow !, very good ! Have a good chrismast holyday ! Megaben3
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