Palmerj Posted March 1, 2012 Share Posted March 1, 2012 (edited) Hello, Wondering if anyone has experienced unreliable returns from FileFindFirstFile. I have a script running from a WinPE environment that maps a network share then checks to see if the expected number of files with the same name pattern exist. The function below is called with "p:sharefile00*.bin", 10 There are exactly 10 files in the share named file001.bin, file002.bin... up to file0010.bin. The first time, the funtion immediately returns -1, but if I call it repeatedly with the exact same parameter values, it finally works. Func _VerifySpan($fpath, $fcount) $fc = 0 $fh = FileFindFirstFile($fpath) If $fh = -1 Then Return False ; First file not found While 1 $fn = FileFindNextFile($fh) If @error = 1 Then ExitLoop $fc = $fc + 1 WEnd FileClose($fh) If $fcount = $fc Then Return True Else Return False EndFunc Edited March 1, 2012 by Palmerj Link to comment Share on other sites More sharing options...
jchd Posted March 1, 2012 Share Posted March 1, 2012 It may be that the OS needs "some time" right after mapping a share to "discover" its actual existence and access its contents. A similar effect is observed right after connecting to a LAN, where shares are only accessible after a while. If that's the issue, there's little AutoIt can do by itself against that. What you can try is to test the share itself for existence with FileExists until it returns nonzero then proceed with your function to see if that makes a difference. Palmerj 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Palmerj Posted March 1, 2012 Author Share Posted March 1, 2012 I had done something similar; dropping the FileFindNextFile() into a While loop with a half second sleep in between calls, with the loop executing a maximum of 10 iterations. This seems to work, but it has the effect of delaying response when a file is really missing. Appreciate your suggestion; I'll try that instead. Thanks. Link to comment Share on other sites More sharing options...
kylomas Posted March 1, 2012 Share Posted March 1, 2012 Palmerj, I believe that jchd is suggesting that you test for "p:share" before testing for specific files. kylomas Forum Rules        Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
MrAutomationGuy Posted March 1, 2012 Share Posted March 1, 2012 This is what I do in my script1) I first make sure I can connect to UNC path (Net use.....) command<computer>p$This allows the network connectivity to happen before I try to access the disk for file i/o.2) Then I perform my disk activity (Copy/Delete, blah blah).This works for me 100% of the time.Just a suggestionMr.AutomationGuy Link to comment Share on other sites More sharing options...
Palmerj Posted March 2, 2012 Author Share Posted March 2, 2012 Palmerj,I believe that jchd is suggesting that you test for "p:share" before testing for specific files.kylomasYes, I understood what he suggested.However, before his post, I was calling the function repeatedly until it worked. Once I read his post, I switched to checking the directory.I agree this is a better solution and give him full credit. Link to comment Share on other sites More sharing options...
jchd Posted March 2, 2012 Share Posted March 2, 2012 AutomationGuy, In your testing, did you find that accessing the share using an UNC path established network connectivity (or rather share "awareness") faster than accessing it by share local net name (Y:share)? And if there is a difference, on which OS version? I'm curious because this is a very common problem with Win LANs (with no domain) and finding the best reliable way to deal with that annoying latency would be good to know. Note: I can't test here with my single poor machine. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
guinness Posted March 2, 2012 Share Posted March 2, 2012 (edited) A quick test on Windows 7 x64 & I found using the share name e.g. K:Something was quicker than using the UNC path. But as you can see from the results it wasn't a huge difference. Local $iTimer $iTimer = TimerInit() For $i = 1 To 5000 FileExists("NAS-PCFiles") Next ConsoleWrite(FileExists("NAS-PCFiles") & @CRLF) ConsoleWrite(TimerDiff($iTimer) / 5000 & @CRLF) $iTimer = TimerInit() For $i = 1 To 5000 FileExists("N:") Next ConsoleWrite(FileExists("N:") & @CRLF) ConsoleWrite(TimerDiff($iTimer) / 5000 & @CRLF) 1 0.138702804631814 1 0.125354104256387 Edited March 2, 2012 by guinness 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
MrAutomationGuy Posted March 2, 2012 Share Posted March 2, 2012 AutomationGuy,In your testing, did you find that accessing the share using an UNC path established network connectivity (or rather share "awareness") faster than accessing it by share local net name (Y:share)? And if there is a difference, on which OS version?I'm curious because this is a very common problem with Win LANs (with no domain) and finding the best reliable way to deal with that annoying latency would be good to know. Note: I can't test here with my single poor machine.I just tried again, it stablished network connectivity and keept it alive. (That's why it is asking for the user/pass in the net use command). I agree with previous poster that in your case you might want to maybe first "CD" to that path, wait for a while, then do your stuff, see if that works.M.A Link to comment Share on other sites More sharing options...
jchd Posted March 2, 2012 Share Posted March 2, 2012 In short no magic wand. Thanks both of you for trying. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
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