Jump to content

Refresh on FileExists


m00
 Share

Recommended Posts

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")
sleep(5000)
WEnd

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
Link to comment
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")
sleep(500)
ConsoleWrite("notfound")
WEnd
MsgBox(0,"its there","file exists!",5)
$file1 = 0
WEnd
Exit

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.

Cheers

Link to comment
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
        ExitLoop
    EndIf
    Sleep(100)
    $iCount += 1
WEnd
If $iCount Then
    ConsoleWrite("Found" & @LF)
Else
    ConsoleWrite("NOT Found" & @LF)
EndIf

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_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: 22/04/2018

Link to comment
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?

Link to comment
Share on other sites

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)
   Exit
EndIf
;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)
FileWriteLine($inireg,"[Transaction]")
FileWriteLine($inireg,"[Users]")
FileClose($inireg)

IniWrite("C:interfacesharetest1.ini","Transaction","Step","1")

Computer B - the Virtual Machine

(Z: is mapped to hostpcinterfaceshare )

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

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
Link to comment
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.

Cheers

Link to comment
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.

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

×
×
  • Create New...