Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Scripting_function


Panel
titleDescription

Checks to see if a file or folder at a given path exists.

Note_friendly

This function is scoped for Perspective Sessions, but since all scripts in Perspective run on the Gateway, the file must be located on the Gateway's file system. 

Client permissions restrictions


Panel
titleSyntax

system.file.fileExists(filepath)

  • Parameters

String filepath - The path of the file or folder to check.

  • Returns

Boolean - True if the file/folder exists, false otherwise.

  • Scope

Gateway, Vision Client, Perspective Session

Panel
titleCode Examples
Code Block
languagepy
titleCode Snippet
# This basic example shows how the fileExists function is used in its simplest form:
if system.file.fileExists("C:\\temp_file.txt"):
   system.gui.messageBox("Yes, the file exists")
else:
   system.gui.messageBox("No, it doesn't exist")
Code Block
languagepy
titleCode Snippet
# This code uses the fileExists function, along with other system.file.* functions, to prompt the user to confirm that they want to overwrite an existing file.
filename = system.file.saveFile("")
if filename is not None:
   reallyWrite = 1
   if system.file.fileExists(filename):
      overwriteMessage = "File '%s' already exists. Overwrite?"
      reallyWrite = system.gui.confirm(overwriteMessage % filename)
   if reallyWrite:
      system.file.writeFile(filename, "This will be the contents of my new file")
Panel
titleKeywords

system file fileExists, file.fileExists