PowerBasic Museum 2020-A

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Windows Script Runtime => Source Code => Scripting => FileSystemObject => Topic started by: José Roca on July 14, 2008, 02:58:29 AM

Title: IFileSystem.FileExists
Post by: José Roca on July 14, 2008, 02:58:29 AM


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