File.exists()

NES2+Syntax

							file.exists()

Description

The exists() method of the File object returns a boolean value based on the existence of the file in which it was invoked. If the file exists, the method returns true. It returns false if the file does not exist.

Example

Listing 8.76 opens a file and then checks to see if it exists.

Listing 8.76 Using the exists() Method to See If a File Exists
<SERVER>

// Open a log file
var myLog = new File("/data/logs/today.log");

// See if the file exists
if(myLog.exists()){
  write('The file exists');
}else{
  write('The file does not exist');
}

</SERVER>
						

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.