Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking file
Message
From
22/09/2001 12:54:08
 
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00559665
Message ID:
00559667
Views:
17
>Hi All,
>
>Is there any VB command/function that checks a file if exist in the directory or not and return False/True?
>
>BR

Ahmad,

The Dir() function can be used for this although it returns an empty string ("") if the file does not exist. If it absolutely has to return True or False you can create your own function that captures the return value of Dir() and returns True or False depending on the return value of Dir(). The syntax for its use is something like:
If Dir("c:\mypath\myfile.txt") = "" Then
  'code to indicate the file does not exist
Else
  'code to work with the file
Endif
Although not a VB command or function, you can use the FileSystemObject also and it does have the FileExists() function that returns True/False if the file exists or not. Add a reference to the MS scripting runtime and then do something like:
Dim FSO as Scripting.FileSystemObject
Set FSO = New Scripting.FileSystemObject
Debug.Print FSO.FileExists("C:\mypath\myfile.txt")
Hope this helps.
Previous
Reply
Map
View

Click here to load this message in the networking platform