Skip to main content

FileSystemObject.FileExists method

Table of contents
  1. Syntax
  2. Examples

Returns True if a specified file exists; False if it does not.

Syntax

object.FileExists (filespec)

The FileExists method syntax has these parts:

Part Description
object Required. Always the name of a FileSystemObject.
filespec Required. The name of the file whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the file isn't expected to exist in the current folder.

Examples

Below examples assume file "D:\Temp\Readme.txt" exists and no other files exist in the folder "D:\Temp".

Sub FileExistsDemo()
    Dim fso As Object, f As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
 
    Debug.Print fso.FileExists("D:\Temp\Readme.txt") 'Result: True
    Debug.Print fso.FileExists("C:\Temp\Products.txt") 'Result: False
End Sub

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>