Checking for existence of a file??? 
Author Message
 Checking for existence of a file???

Is the only way to safely test for the existence of a file
to try to open it for input?

Thanks,
Pete



Tue, 22 Apr 2003 02:23:15 GMT  
 Checking for existence of a file???
Try this

Dim File    As String

File=DIR("<Path><Filename>")
IF File <> "" then FileExists

Regards
Zeiss


Quote:
> Is the only way to safely test for the existence of a file
> to try to open it for input?

> Thanks,
> Pete



Tue, 22 Apr 2003 03:25:00 GMT  
 Checking for existence of a file???
No...  You can use the FileExists method of the FileSystemObject object.

Jennifer



Quote:
> Is the only way to safely test for the existence of a file
> to try to open it for input?

> Thanks,
> Pete

Sent via Deja.com http://www.deja.com/
Before you buy.


Tue, 22 Apr 2003 03:39:57 GMT  
 Checking for existence of a file???


Quote:
>Is the only way to safely test for the existence of a file
>to try to open it for input?

I think not.

Try...

z$ = Dir$(drive:\path\filname.ext)

If z$="" then
        <It doesn't exist>
Else
        <Yes, it exists>
End If

HTH

Regards,

--
Martin Trump



Tue, 22 Apr 2003 03:41:33 GMT  
 Checking for existence of a file???
: Try this
:
: Dim File    As String
:
: File=DIR("<Path><Filename>")
: IF File <> "" then FileExists

Just out of curiosity, will File's value be the complete
pathname?



Tue, 22 Apr 2003 08:19:23 GMT  
 Checking for existence of a file???
For most of my situations, I find the FileSystemObject the best way.
    You can not only check for it's existence, you can make conditional
procedures based on if it exists or not.
    dim fso as new filesystemobject
    if fso.fileExists(yourfilepath) = true then
        one procedure
    else
        another procedure
    end if
FileSystemObject requires Microsoft scripting runtime reference, but it is
fairly easy to figure out how to make it all work.
    Hope this helps...
    Dan
--
Dan & Carmella Dunkin
Danella Creations
<http://www.danellacreations.com>
---------------------------------------------
Don't squat with your spurs on-
 Will Rodgers
----------------------------------------------

Quote:
> Is the only way to safely test for the existence of a file
> to try to open it for input?

> Thanks,
> Pete



Tue, 22 Apr 2003 11:13:15 GMT  
 Checking for existence of a file???
: For most of my situations, I find the FileSystemObject the best way.
:     You can not only check for it's existence, you can make conditional
: procedures based on if it exists or not.

  Don't forget that no file check can guarantee that the file exists after
the text reports the result.  There is a real possibility that the file
will vanish between the time the check is perfomed and an attempt is made
to open it.

  This <is> a multitasking environment after all.



Tue, 22 Apr 2003 11:54:59 GMT  
 Checking for existence of a file???
: Is the only way to safely test for the existence of a file
: to try to open it for input?

  FindFirst.



Tue, 22 Apr 2003 11:50:49 GMT  
 Checking for existence of a file???
Using Dir is dangerous - it can interfere with other uses of Dir.

Function FileExists( Fle$ ) As Boolean
    Dim Attrib%

    On Error Resume Next
    Attrib = GetAttr(Fle$)
    If Err = 0 Then
       If (Attrib And vbDirectory) = vbDirectory = 0 Then
          FileExists = True
       End If
    End If
    On Error Goto 0

End Function



Quote:

>: Is the only way to safely test for the existence of a file
>: to try to open it for input?

>  FindFirst.



Tue, 22 Apr 2003 17:53:13 GMT  
 Checking for existence of a file???
No, FILE will only contain the file's name, which is quite handy.

This allows for wild charater use * ? etc (*.mst or whatever)

Repeated calls of FILE= DIR() will return all files matching the criteria
and ="" when all done

Regards
Zeiss


Quote:

> : Try this
> :
> : Dim File    As String
> :
> : File=DIR("<Path><Filename>")
> : IF File <> "" then FileExists

> Just out of curiosity, will File's value be the complete
> pathname?



Tue, 22 Apr 2003 19:28:10 GMT  
 Checking for existence of a file???
: Using Dir is dangerous - it can interfere with other uses of Dir.

Would you please explain that statement?

Thanks,
Pete


:

: >: Is the only way to safely test for the existence of a file
: >: to try to open it for input?
: >
: >  FindFirst.



Wed, 23 Apr 2003 09:18:58 GMT  
 Checking for existence of a file???


Quote:

> : Using Dir is dangerous - it can interfere with other uses of Dir.

> Would you please explain that statement?

You write a routine that checks for a file using Dir$.  It works and
you use it for a while.

Later on you write a routine that processes a given file some way.  In
that routine you check for existence using the first routine that you
know works well.  This new procedure also works and you use it for a
while.

You decide to process all files in a directory so you use Dir$ to get
each entry and then call your file processing routine.  It blows up for
no apparent reason....  your call to Dir$ two levels down has screwed
up the top-level Dir$ loop.

(been there, done that <g>)

--
Please reply via the newsgroup only

Sent via Deja.com http://www.deja.com/
Before you buy.



Wed, 23 Apr 2003 10:53:46 GMT  
 Checking for existence of a file???
Say again, over!

Mike


Quote:



> > : Using Dir is dangerous - it can interfere with other uses of Dir.

> > Would you please explain that statement?

> You write a routine that checks for a file using Dir$.  It works and
> you use it for a while.

> Later on you write a routine that processes a given file some way.  In
> that routine you check for existence using the first routine that you
> know works well.  This new procedure also works and you use it for a
> while.

> You decide to process all files in a directory so you use Dir$ to get
> each entry and then call your file processing routine.  It blows up
for
> no apparent reason....  your call to Dir$ two levels down has screwed
> up the top-level Dir$ loop.

> (been there, done that <g>)

> --
> Please reply via the newsgroup only

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Wed, 23 Apr 2003 11:33:10 GMT  
 Checking for existence of a file???
: Say again, over!

  You can't nest a dir within a dir.  If you try it, dir 0 will take on
the characteristics of dir 1.



Wed, 23 Apr 2003 12:55:43 GMT  
 Checking for existence of a file???

: : Using Dir is dangerous - it can interfere with other uses of Dir.

: Would you please explain that statement?

  If you are in the middle of displaying a directory - or processing one,
then using the directory function to check if a file exists will alter the
way the remaining program lists/processes the directory.

  Generally it won't be an issue.



Wed, 23 Apr 2003 12:53:56 GMT  
 
 [ 17 post ]  Go to page: [1] [2]

 Relevant Pages 

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

2. Check for existence of a file?

3. Checking for existence of a file...

4. Checking the Existence of a File

5. A2K Check for Existence of Back End File

6. Checking for the existence of a file

7. Check File Existence?

8. Checking for the Existence of a File

9. Checking for random file existence in Visual Basic

10. Check for the existence of a file.

11. Newbie Question: File existence checking

12. file existence check

 

 
Powered by phpBB® Forum Software