Check for the existence of a file. 
Author Message
 Check for the existence of a file.

Is there any easy way to check for the existence of a file?

Any help is appreciated.



Mon, 23 Apr 2001 03:00:00 GMT  
 Check for the existence of a file.
if you only want to check for a name:

debug.print Dir$("C:\Autoexec.bat")
(Empty if it doesn't exist)

Best regards

Quote:

>Is there any easy way to check for the existence of a file?

>Any help is appreciated.



Tue, 24 Apr 2001 03:00:00 GMT  
 Check for the existence of a file.

writes
Quote:
>Is there any easy way to check for the existence of a file?

>Any help is appreciated.

Try this...

Public Function FileExists(fname As string) As Boolean
        Dim f1 As Integer
        Dim ret as Boolean
        f1 = Freefile
        ret = True
        On Error Goto FileExistsErr
        Open fname For Input As f1
        Close F1
        FileExists = ret
        Exit Function

FlieExistsErr:
        Ret = False
        Resume Next
End Function
--
David Sinfield (Surrey, UK)
Not clever enough to make up a sig
and too proud to steal one.



Tue, 24 Apr 2001 03:00:00 GMT  
 Check for the existence of a file.
Quote:
>Public Function FileExists(fname As string) As Boolean
>        Dim f1 As Integer
>        Dim ret as Boolean
>        f1 = Freefile
>        ret = True
>        On Error Goto FileExistsErr
>        Open fname For Input As f1
>        Close F1
>        FileExists = ret
>        Exit Function

>FlieExistsErr:
>        Ret = False
>        Resume Next
>End Function
>--

You could do it like this if you wanted - a far better and IMO more elegant
approach would be
        FileExists = not (Dir$(FileName) = space(0))


Tue, 24 Apr 2001 03:00:00 GMT  
 Check for the existence of a file.
Much Thanks to all.
Quote:

>Is there any easy way to check for the existence of a file?

>Any help is appreciated.



Tue, 24 Apr 2001 03:00:00 GMT  
 Check for the existence of a file.
If Dir("file.ext") <> "" Then FileExists

--
Andreas Swensson

Quote:

>Is there any easy way to check for the existence of a file?



Tue, 24 Apr 2001 03:00:00 GMT  
 Check for the existence of a file.
Here is a function I use:

Function FileExist (ByVal fname As String) As Integer
    On Error Resume Next
    FileExist = Dir$(fname, 0) <> ""
    If Err <> 0 Then FileExist = False
End Function

I also have a similar function to check for a directory, changing the 0
parameter in the Dir$ function to a 16.

Hope it helps!

Rob

Quote:

> Is there any easy way to check for the existence of a file?

> Any help is appreciated.

--
Robert Nitsos
Programmer/Analyst
Client Accounting Systems, Inc.

http://www.clientaccounting.com


Tue, 24 Apr 2001 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Checking for the existence of a file

2. Checking for the Existence of a File

3. Check for the existence of the file

4. A2K Check for Existence of Back End File

5. How to check for existence of a file on harddisk form OL VBscript

6. Check File Existence?

7. Checking for random file existence in Visual Basic

8. Checking for existence of a file???

9. Check for existence of a file?

10. Checking for existence of a file...

11. Checking the Existence of a File

12. Newbie Question: File existence checking

 

 
Powered by phpBB® Forum Software