system.file.fileExists
This function is used in Python Scripting.
Description​
Checks to see if a file or folder at a given path exists.
note
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 Permission Restrictions​
This scripting function has no Client Permission restrictions.
Syntax​
system.file.fileExists(filepath)
Parameters​
Type | Parameter | Description |
---|---|---|
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
Code Examples​
Example #1
# 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")
Example #2
# 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(name)
if filename != 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")