Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a FILES

Status
Not open for further replies.

desprits

Programmer
Feb 14, 2004
40
0
0
CA
I would like to know what should I do to know if a files exist in VB.

Exemple : if File1 exist then
else
Create File1
endif
 
create a reference to microsoft scripting runtime, under references in the project menu. Then use the following code:

Dim FSO As FileSystemObject

Set FSO = New FileSystemObject

If FSO.FileExists("C:\Folder\worddoc.doc") = True Then 'file exists

else 'file not present.

End if

BB
 
What the refecence of that ?

FileSystemsObject
 
As BiggerBrother said the normal reference required to get access to the FileSystemObject is the Microsoft Scripting Runtime
 
Far easier IMO is the Dir$() function:

Code:
If LenB(Dir$("C:\yourfile.txt")) = 0 Then
    ' file does not exist, create it
Else
    ' file exists
End If

The Dir$() function will return a nullstring if the file does not exist.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top