system.file.fileExists
Description
Checks to see if a file or folder at a given path exists.
Syntax
system.file. fileExists( filepath )
-
Parameters
String filepath - The path of the file or folder to check.
-
Returns
boolean - True (1) if the file/folder exists, false (0) otherwise.
-
Scope
All
Code Examples
Code 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 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(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")