FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Reliable File Access in Network Environments โ€“ Combining DIRECTORY() and FILE()
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Reliable File Access in Network Environments โ€“ Combining DIRECTORY() and FILE()
Posted: Fri Jul 18, 2025 09:04 AM
Hello friends,

In some of our recent projects, we encountered issues with file-based applications running over network drives โ€“ especially when the connection was temporarily lost (e.g. via WLAN, sleeping NAS, or Windows caching).
A standard FILE() check often fails in these cases, even though the file is still accessible (e.g. cached or available again after a few seconds).

To address this, weโ€™ve created a small helper function that combines DIRECTORY() and FILE() to check both network availability and file existence more reliably.

Ensure safe .DBF access in less stable network environments

Prevent unwanted file creation due to false negatives from FILE()

Optionally integrate logging or user feedback

Best regards,
Otto
FUNCTION SafeFileExists( cPath )
   // First, check if the network path responds
   IF empty( DIRECTORY( cPath ) )
      RETURN .F.
   ENDIF

   // Then check if the file really exists
   RETURN FILE( cPath )
ENDFUNCTION

Continue the discussion