Jump to content

FileExists() takes too long for an invalid UNC path


 Share

Recommended Posts

I have a desktop and a notebook connected through a common router. In the notebook I have a code which checks if there is a file in the desktop. 

If FileExists("\\Desktop-Main\D\Data\list.txt") Then
    ; some code here
Else
    ; some other code here
EndIf

This works fine when the notebook is connected to the desktop. When it is not, however, the code is hung for about 25 seconds until the FileExists function returns a 0 value. Even Ping("Desktop", 10) takes more than 2000 milliseconds. I would like to know if there is a quicker way to check the existence of a UNC path.

Take a good care of your health.

Edited by CYCho
Link to comment
Share on other sites

Below is the result of my tests:

$t = TimerInit()
$f1 = Ping("desktop-main", 10) ;
$t1 = TimerDiff($t)
$t = TimerInit()
$f2 = FileExists("\\desktop-main\d\data")
$t2 = TimerDiff($t)
ConsoleWrite("Ping result: " & $f1 & ", " & $t1 & @CRLF & "FileExists result: " & $f2 & ", " & $t2 & @CRLF)

1. Console output when the notebook is connected

>"C:\AutoIt\SciTE\..\AutoIt3.exe" "C:\AutoIt\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\T-Clock_static\Temp.au3" /UserParams    
+>14:10:54 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0   Keyboard:00000412  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0412)  CodePage:949  utf8.auto.check:4
+>         SciTEDir => C:\AutoIt\SciTE   UserDir => C:\Users\CYCho\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\CYCho\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\AutoIt  input:C:\T-Clock_static\Temp.au3
+>14:10:54 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\AutoIt\autoit3.exe "C:\T-Clock_static\Temp.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
Ping result: 14, 34.6601
FileExists result: 1, 0.3269
+>14:10:54 AutoIt3.exe ended.rc:0
+>14:10:54 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.01


2. Console output when the notebook is disconnected

>"C:\AutoIt\SciTE\..\AutoIt3.exe" "C:\AutoIt\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\T-Clock_static\Temp.au3" /UserParams    
+>14:20:27 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.4.1.2.0   Keyboard:00000412  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0412)  CodePage:949  utf8.auto.check:4
+>         SciTEDir => C:\AutoIt\SciTE   UserDir => C:\Users\CYCho\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\CYCho\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\AutoIt  input:C:\T-Clock_static\Temp.au3
+>14:20:27 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\AutoIt\autoit3.exe "C:\T-Clock_static\Temp.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
Ping result: 0, 2566.4348
FileExists result: 0, 23262.1627
+>14:20:53 AutoIt3.exe ended.rc:0
+>14:20:53 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 26.75
 

Link to comment
Share on other sites

Can you ping the router first?

This seems weird, but it can't hurt... Have you tried mapping the drive? Maybe trying/checking for the drive would go faster?

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

@CYCho  I was also interested by that issue, so I tested a few different ways :

1- shell.application object

2- DOS if exists

3- WinAPI_FileExists

4- File* functions

All give more or less the same timeout delay.  I believe the solution provided by Gibbo is the best there is...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...