|
-
Jun 24th, 2000, 10:58 PM
#1
Thread Starter
Member
i need a function that returns true or false, wether a file exists or not
-
Jun 24th, 2000, 11:30 PM
#2
Fanatic Member
Here you go... Add a textbox and a commandbutton to a form to test this example:
Code:
Private Sub Command1_Click()
If Dir(Text1.Text) <> "" Then
MsgBox "File """ & Text1.Text & """ found!"
Else
MsgBox "File """ & Text1.Text & """ not found!"
End If
End Sub
www.RealisticGraphics.net
Running VS.Net Enterprise & VB 6
Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML
MSN Messenger: kmsheff
-
Jun 25th, 2000, 02:47 AM
#3
Addicted Member
You can use the following code as a function
Function File_Exist(FileName As String) As Integer
Dim Cp As Integer
On Local Error Resume Next
Cp = FreeFile
Open FileName For Input As Cp
File_Exist = IIf(Err, True, False)
Close Cp
Err = 0
End Function
-
Jun 25th, 2000, 07:24 AM
#4
PowerPoster
Juz use Dir function is enough.
-
Jun 25th, 2000, 07:51 AM
#5
Code:
Public Function fileexists(strfilepathandname As String) As Boolean
On Error Resume Next
Dim lngcheck As Long
If InStr(strfilepathandname$, ".") = 0& Then
Let fileexists = False
End If
Let lngcheck& = Len(Dir$(strfilepathandname$))
If lngcheck& = 0& Then
Let fileexists = False
Exit Function
Else
Let fileexists = True
End If
Exit Function
End Function
'Usage:
'If fileexists("C:\Autoexec.bat") Then
'Msgbox "file exists."
'Else
'Msgbox "file does not exist."
'End If
-
Jun 25th, 2000, 07:59 AM
#6
Hyperactive Member
Use FSO
Code:
'Declaration
Set fso = CreateObject("Scripting.FileSystemObject")
Syntax: object.fileexists (filespec)
'Example:
If fso.FileExists("C:\Windows\win.com") Then
'Code if exists
Else
'Code if not
End If
Signed, Rodik ([email protected])
Programmer,usesVB6ED
===========================
Copyright©RodikCo,2002.
Dont mind this signature ;] Its old
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|