Jump to content
Sign in to follow this  
Palmerj

FileFindFirstFile() unreliable

Recommended Posts

Palmerj

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 by Palmerj

Share this post


Link to post
Share on other sites
jchd

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.

  • Like 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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
Palmerj

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.

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
MrAutomationGuy

This is what I do in my script

1) 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 suggestion

Mr.AutomationGuy

Share this post


Link to post
Share on other sites
Palmerj

Palmerj,

I believe that jchd is suggesting that you test for "p:share" before testing for specific files.

kylomas

Yes, 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.

Share this post


Link to post
Share on other sites
jchd

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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites
guinness

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 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 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

Share this post


Link to post
Share on other sites
MrAutomationGuy

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

Share this post


Link to post
Share on other sites
jchd

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 here
RegExp tutorial: enough to get started
PCRE 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)

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  

  • Similar Content

    • DavidLago
      By DavidLago
      Hello. 
      I need to list only the folders that has a name composed of numbers only.
      How do I do this?
      OBS: I just posted the relevant content to the folder.
      Global $path = "G:\jobs\" For $i = 1 To $aArray[0] Local $search = FileFindFirstFile($path & $aArray[$i] & "\[0-9]" ) I tried with "\*.*" and it returns me the expected result, but the other doesn't.
    • NiceBoy1234
      By NiceBoy1234
      So I tried to get the first file of a folder with FileFindFirstFile but it always gives me a 1 as a value, so it tells me that the folder is empty.
      But the folder is not empty.
      Code:
      Local $path_times_text_01 = "D:\xxx\test\xxx\" Local $search = FileFindFirstFile($path_times_text_01 & "*.*") Timecheck() Func Timecheck() ConsoleWrite($search & @CRLF) If $search = -1 Then MsgBox(0, "Error", "could not find extension") Exit EndIf If $search = 1 Then MsgBox(0, "Fehler", "folder is empty") Exit EndIf ConsoleWrite($search & @CRLF) EndFunc This does not make any sense to make because again the folders are not empty.
    • tes5884
      By tes5884
      The program is supposed to search for *.pst files, then copy the results to a server share.
      What am I doing wrong? It doesn't seem to be doing anything.


      $nMsg = GUIGetMsg() Switch $nmsg Case $bckuppst While 1 $pst1=FileFindFirstFile("*.pst") FileCopy($pst1, "\\majordc01\backups\" & @UserName, 8) $pst2=FileFindNextFile($pst1) FileCopy($pst2, "\\majordc01\backups\" & @UserName, 8) if @error then ExitLoop WEnd EndSwitch
      Thanks!
×