The following example illustrates the use of the
FileExists method.
JScript
function ReportFileStatus(filespec)
{
var fso, s = filespec;
fso = new ActiveXObject("Scripting.FileSystemObject");
if (fso.FileExists(filespec))
s += " exists.";
else
s += " doesn't exist.";
return(s);
}
VBScript
Function ReportFileStatus(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
ReportFileStatus = msg
End Function
PowerBASIC
FUNCTION ReportFileStatus (BYVAL strFileSpec AS STRING) AS STRING
LOCAL fso AS IFileSystem
LOCAL strMsg AS STRING
fso = NEWCOM ("Scripting.FileSystemObject")
IF fso.FileExists(UCODE$(strFileSpec)) THEN
strMsg = strFileSpec & " exists."
Else
strMsg = strFileSpec & " doesn't exist."
End If
FUNCTION = strMsg
END FUNCTION