지정된 파일이 있는 경우 True를 반환하고, 없는 경우 False를 반환합니다.
구문
object.FileExists(filespec)
인수:
FileSystemObject의 이름입니다.다음 예에서는 FileExists 메소드의 사용을 보여 줍니다.
예 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.
예 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.