Check to see if a file exits... 
Author Message
 Check to see if a file exits...

Quote:

>Does anyone know the function that you call to see if a file exists?
>I used to know the function but I forgot and can't bring up anything in the
>help.

        If Len(Dir(sMyFile)) > 0 then
                '''File Exists
        Else
                '''File Doesn't Exist
        End If

Lee Weiner
weiner AT fuse DOT net



Sat, 02 Sep 2000 03:00:00 GMT  
 Check to see if a file exits...

Does anyone know the function that you call to see if a file exists?
I used to know the function but I forgot and can't bring up anything in the
help.
Any help would be appreciated.
Thanx



Sat, 02 Sep 2000 03:00:00 GMT  
 Check to see if a file exits...

There are a couple of ways to check if a file exists.....

1. Use DIR$
        Dim sFile$
        sFile = "C:\xyz.txt"
        If Dir$(sFile, vbNormal) <> "" Then     ' the file exists

2. Use FileLength() --- requires error handling
        Dim sFile$, dwLength&
        sFile = "C:\xyz.txt"
        On Error Resume Next
        dwLength = FileLength(sFile)
        If Err.Number = 0 Then          ' the file exists

3. Use OpenFile() API call --- more sophisticated, but works really well
        ' in global area
        Type OFSTRUCT
                cBytes            As Byte
                fFixedDisk        As Byte
                nErrCode          As Integer    ' or Long for Win32
                rsvd              As Long
                szPathName        As String * 128
        End Type
        Public Const OF_EXIST = &H4000
        Public Const HFILE_ERROR = -1

        Declare Function OpenFile% Lib "KERNEL" (ByVal lpszFile As Any, ofs As
OFSTRUCT, ByVal uFlags%)

        ' in routine
        sFile = "C:\xyz.txt"
        Dim ofs As OFSTRUCT
        With ofs
                .cBytes = Len(ofs)
                .fFixedDist = 0
                .nErrCode = 0
                .rsvd = 0
                .szPathName = String$(128, Chr$(0))
        End With
        If (OpenFile(ByVal sFile, ofs, OF_EXIST) <> HFILE_ERROR) Then             ' the file
exists

Normally, I use the API routine. I have a routine that calls it that I use
in all my apps. This method is nice because it will never generate a
run-time error if the file doesn't exist. You only need to check the return
value.

Hope this helps,
W. Clifford



Quote:
> Does anyone know the function that you call to see if a file exists?
> I used to know the function but I forgot and can't bring up anything in
the
> help.
> Any help would be appreciated.
> Thanx




Sat, 02 Sep 2000 03:00:00 GMT  
 Check to see if a file exits...

Dir is the function you require
if dir("c:\myfile.txt")="c:\myfile.txt" then        'your file exists



Quote:
> Does anyone know the function that you call to see if a file exists?
> I used to know the function but I forgot and can't bring up anything in
the
> help.
> Any help would be appreciated.
> Thanx




Sat, 02 Sep 2000 03:00:00 GMT  
 Check to see if a file exits...

the function is dir$()
if dir$(filename) ="" then
      file does not exist
else
     file exist
endif



Mon, 04 Sep 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Seeing which radio button is checked?

2. File/Opens sees file names as ?????????1

3. Check Out Of Office status on exit

4. Add Spell Check rules upon save or exit?

5. Check for Menubar if exist - exit sub

6. Check when a program starts or exits

7. Toolhelp.dll (Check when DLL or EXE starts or exits)

8. Toolhelp.dll (check when a DLL or EXE is started or exit)

9. ? text file format i have seen?

10. Bizarre problem - VB6 won't see one .EXE file but sees all others

11. Seeing if a file/program is in memory/running

12. Anyone seen this error: File/Path access error.

 

 
Powered by phpBB® Forum Software