JavaScript

{dialog.object}phoneGapFileExistsURL Method

Syntax

{dialog.object}.phoneGapFileExistsURL(filepath,onResult,onError);

Arguments

filepath

Local file URL of the desired file.

onResult

A Javascript function called on success. This function takes one parameter, properties. If the file is not found, properties will have a value of false. If the file is found, properties will be a JSON object with the following values:

name

The file name.

lastModifiedDate

lastModifiedDate object

size

size of the file in bytes

type

MIME type of the file if known (MIME type is not available on iOS, but is available on Android.)

onError

A javascript function that is called if an error occurs. This function takes one parameter, e, which contains information about the error.

Description

Check if a file exists. If the file does exist, a callback function is called with the properties of the file (such as size, date last modified, etc.)

Example

var onResult = function(properties) { 
    if (properties == false) {
        alert("File does not exist.");
    } else {
        alert("File exists!");
    }
};
var onError = function(e) { 
    alert("An error occured!");
};
var filepath = {dialog.object}.phoneGapGetLocalDirURL('private') + 'file.txt';
{dialog.object}.phoneGapFileExistsURL(filepath, onResult, onError);