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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.