Sign in to follow this  
Followers 0

Refresh on FileExists

7 posts in this topic

#1 ·  Posted (edited)

So I am running a couple of computers on a local network.

I am attempting to use FileExists to trigger events on an Autoit program running on each of them.

Computer A makes a file (text1.txt) in a shared directory. Meanwhile, Computer B is running a tight loop with FileExists, checking for that file in a mapped drive:

While $file1 = 0
$file1 = FileExists("Z:text1.txt")

However, when I put in some tracking (ConsoleWrite) things, it appears that it is only checking the Z: directory one time, and even when there is the 'text1.txt' file there after a couple of loops, it won't leave the loop.

Is there something I should be doing to make FileExists "refresh" the directory? Should I be using something else to interface between the two machines?

I could probably do a FileOpen, check for a particular line, and then FileClose.... it seems like more than I should need for this though.

Suggestions anyone?

Edited by m00

Share this post

Link to post
Share on other sites

I have had a look at this on my test network and it seems to work just fine.

The code i used is

Dim $file1
Dim $counter
$counter = 0
While $counter = 0
While $file1 = 0
$file1 = FileExists("Y:temptext1.txt")
MsgBox(0,"its there","file exists!",5)
$file1 = 0

Is there perhaps anything else that is effecting it. What happens if you create the file on the computer that is monitoring the folder, in case the folder/drive is getting cached and not refreshed by the looker. however in my case i did exactly as you said, and created the file from a second computer without the auto it computer haveing that folder opened in explorer to rule out some other app causing the refresh of data.


Share this post

Link to post
Share on other sites

Another way with only 1 loop this time.

Local $iCount = 1
While FileExists("C:FILEPATH") = 0
    If $iCount = 100 Then ; 10 seconds in total.
        $iCount = 0
    $iCount += 1
If $iCount Then
    ConsoleWrite("Found" & @LF)
    ConsoleWrite("NOT Found" & @LF)

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post

Link to post
Share on other sites

Thanks for the replies. I'm not really concerned about the loop so much as the file check.

It may be an issue with the way this drive is mapped. The computer running the Autoit script is on a virtual machine, and is mapping a drive to a VM shared folder...It is a little different than just a network shared folder.

I think that I am going to try a similar thing with an .INI file. Same tight loop, but I'll be spamming 'IniRead' and see if that gets me different results.

My last resort will be a FileOpen .... FileClose.

At least in this case, I am sure that FileExists does not work for this particular setup, so I'll be abandoning that. Any other suggestions to try other than the 2 I mentioned above?

Share this post

Link to post
Share on other sites

#5 ·  Posted (edited)

Update: Checking a .ini file works in this instance. I think it must be the way that the VM shared mapped drive works....

Computer A - the host PC

#include <File.au3>
;create/blank the INI
If Not _FileCreate("C:interfacesharetest1.ini") Then
   MsgBox(4096,"Error", " Error Creating/Resetting INI.   error:" & @error)
;I know that I could create this with IniWrite, but I want to have an empty section: [Users]    ...for now
$inireg = FileOpen("C:interfacesharetest1.ini",2)


Computer B - the Virtual Machine

(Z: is mapped to hostpcinterfaceshare )

While $file1 = 0
    $file1 = IniRead("Z:test1.ini","Transaction","Step","0")

Anyway, just posting this in case anyone else has trouble with a VM shared folder update thing. :D

Update 2: I was wrong, this doesn't work. I may try and copy the shared file locally, read it, and then delete it. Maybe that will force it to re-check the shared directory.

Update 3: So none of these worked. I couldn't get the VM to recognize when a remote file was updated, in any instance. Even with a re-call of FileOpen/FileClose. So...I made the file local to the VM, and shared it with the host PC. So far, it looks promising.

Edited by m00

Share this post

Link to post
Share on other sites

Will try with my VM later today, however as there are many number of VM configurations i dont think that if it works on mine that means that it is good for all VM's.

Your best solution might be a fileopen() fileclose() as you have said. Can you try it to see if it will work.


Share this post

Link to post
Share on other sites

Your best solution might be a fileopen() fileclose() as you have said. Can you try it to see if it will work.

Final update: I did try with FileOpen and FileClose. There wasn't a method that I was able to use consistently on the VM that could use a remote (on the host PC) file and consistently ping it. However, it did work in reverse, where the host PC was able to check an .INI for a particular value on a network location (on the VM.)

So....I had the .INI saved locally on the VM, and before I sent the vmrun command to revert to snapshot, I simply copied the .INI to the host, ran the snapshot, and then copied the file back to the VM.

This way, I was able to do a tight loop, checking the local .INI from the VM to determine its next steps.

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
Sign in to follow this  
Followers 0

  • Similar Content

    • lrstndm
      By lrstndm
      Hi all,
      I want to check if a file exists under the System32 folder: C:\Windows\System32\inetsrv\rewrite.dll
      The following code always worked for me:
      $string = @SystemDir & "\inetsrv\rewrite.dll" ConsoleWrite(FileExists($string)) But yesterday I updated my Windows 10 with the last "big" update and now my @SystemDir returns the following string:
      And before it was:
      So I thought I change my code to:
      $string = @WindowsDir & "\System32\inetsrv\rewrite.dll" ConsoleWrite(FileExists($string)) But this code also does not work. I tried to run it as administrator but this also didn't work.
      What am I doing wrong?
    • chipmonger
      By chipmonger
      Have the following code snippet:
      If not FileExists($ExchangeDir & $StockCSV) Then _FileWriteFromArray($ExchangeDir & $StockCSV, $YahooStockEntries) Else When trying to do a check against the non-existent file 'PRN.csv', FileExists is evaluating as True.  This is not happening with other file names, directory structure is correct.
      Any ideas?
    • Gibbo
      By Gibbo
      Hi All, 
      I went searching for something to speed up checking for files on the network (UNC Paths)
      Most examples were rather complicated but someones multi-threaded solution gave me an idea.
      Hope it is useful to someone.
      Seems to work well so far. 
      Func _FileExistsTimeout($sPath, $iTimeout = 1000) Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable. Local $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine "ConsoleWriteError(FileExists(""' & $sPath & '""))"', @ScriptDir, @SW_HIDE, $STDERR_CHILD) Local $sOutput = "" Local $iDiff = 0 While $iDiff < $iTimeout $iDiff = TimerDiff($hTimer) $sOutput &= StderrRead($iPID) If @error Then ; Exit the loop if the process closes or StderrRead returns an error. ExitLoop EndIf WEnd ProcessClose($iPID) Switch StringStripWS($sOutput, 8) Case 1 Return True Case Else Return False EndSwitch EndFunc ;==>_FileExistsTimeout
    • poila
      By poila
      Prior to posting this question, I have experimented with using FileExists, InetGetInfo and InetGet/InetClose functions to test downloading files into my application folder, in case if my file did not already exist.
      In my case, I was able to pinpoint to a very specific web address, eg.), etc. and then check/download the file.
      Now my question is, instead of checking from a hardcoded URL, is it possible to:
      1. Do a check against the IP address of a remote computer, eg.) my friend's or colleague's desktop computer
      2. After checking the IP address if valid and can be connected to, access the computer's hard drive location, eg.) that machine's C:specifiedFolderspecifiedFile.txt
      3. Download a copy of that file into a local computer
      I did read ('?do=embed' frameborder='0' data-embedContent>>) but that was what I accomplished earlier, so now I am not sure if I were to change the method of file retrieval, what changes are necessary?
    • John
      By John
      FileExists returns a false negative if the path string is quoted. Windows sometimes uses these quotes to distinguish between path and argument parts of a path string. Thus a path variable pulled from the registry must have the quotes stripped or FileExists gives a false negative. The dos exist command, comspec and the FileOpenDialog, with the "File Must Exist" flag set, also allows these quotes.

      Fixing this could also provide a method of extend the utility of FileExists and FileOpenDialog's "File Must Exist" flag without breaking any existing scripts. If FileExists optionally allowed these quotes, and only validated the string within the first pair of quotes if they exist, then script developers could easily validate a files existance even when it contains arguments quotes. Such as variables defined by path strings pulled from the registry, user supplied, etc.

      Of course a script developer can easily provide this functionality themselves by providing a wrapper function for FileExists.