Restituisce True se il file specificato esiste. In caso contrario, restituisce False.
Sintassi
object.FileExists(filespec)
Argomenti:
FileSystemObject.Nell'esempio seguente viene illustrato l'uso del metodo FileExists.
Esempio 1
Function CheckFileExists(filespec)
Dim fso, msg
Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(filespec)) Then
msg = filespec & " exists."
Else
msg = filespec & " doesn't exist."
End If
CheckFileExists = msg
End Function
' Sample usage
Dim result
result = CheckFileExists("C:\example.txt")
' Outputs: C:\example.txt exists. or C:\example.txt doesn't exist.
Esempio 2
Function CheckMultipleFiles(files)
Dim fso, file, result
Set fso = CreateObject("Scripting.FileSystemObject")
For Each file In files
If fso.FileExists(file) Then
result = result & file & " exists."
Else
result = result & file & " doesn't exist."
End If
Next
CheckMultipleFiles = result
End Function
' Sample usage
Dim filesToCheck, checkResult
filesToCheck = Array("C:\file1.txt", "C:\file2.txt", "D:\file3.txt")
checkResult = CheckMultipleFiles(filesToCheck)
' Outputs the existence status of each file in the array.