HOWTO: Determine If a File Exists by Using DIR$Last reviewed: March 20, 1997Article ID: Q112674 |
The information in this article applies to:
SUMMARYVisual Basic does not have any built-in functions that tell if a file exists or not. This article demonstrates how to find out if a file exists or not by using a Visual Basic program.
MORE INFORMATIONThere are two different methods you can use to determine if a file exists:
Step-by-Step ExampleThis example show how to check for the existence of a file by using the DIR$ function.
Error in Visual Basic Help File CodePlease note that there is an error in the sample that is provided with the Visual Basic 3.0 Help file (NOTE: This only applies to Visual Basic 3.0, the samples provided with Visual Basic 4.0 and 5.0 are correct). The first line of the following If block is incorrect:
If GetAttr(Path + DirName) And ATTR_DIRECTORY = ATTR_DIRECTORY Then If (Count Mod 10) = 0 Then ReDim Preserve D(Count + 10) ' Resize the array. End If Count = Count + 1 ' Increment counter. D(Count) = DirName End IfHere's the correct version (only difference is the first line):
If GetAttr(path + DirName) = ATTR_DIRECTORY Then If (Count Mod 10) = 0 Then ReDim Preserve D(Count + 10) ' Resize the array. End If Count = Count + 1 ' Increment counter. D(Count) = DirName End If REFERENCESFor more information, see the Programmer's Reference, File Manipulation and the DIR/DIR$ commands.
|
Additional query words: existence
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |