Class: GDDirectoryEntry

GDDirectoryEntry()

An interface representing a directory on the file system.

Constructor

new GDDirectoryEntry()

Properties:
Name Type Description
isFile boolean Always false (readonly)
isDirectory boolean Always true (readonly)
name string Name of the directory, excluding the path leading to it (readonly)
fullPath string The absolute full path to the directory (readonly)
filesystem FileSystem Filesystem on which the directory resides (readonly) - not supported by Cordova
Source:

Methods

copyTo(parent, newName, successCallback, errorCallback)

Copy a directory to a different location.
Parameters:
Name Type Description
parent GDDirectoryEntry The directory to which to copy the entry
newName string New name of the entry, defaults to the current name
successCallback function Called with the new Entry object
errorCallback function Called with a FileError
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var options = {create: true, exclusive: false};

    fileSystem.root.getDirectory("parentDirectory", options, function (parentDirectory) {
        // "/parentDirectory" is created here
        fileSystem.root.getDirectory("nestedDirectory", options, function (nestedDirectory) {
            // "/nestedDirectory" is created here
            nestedDirectory.copyTo(parentDirectory, "newDirectory", function (directory) {
                // now "/nestedDirectory" was copied to "/parentDirectory" with new name "newDirectory"
                console.log(directory.isFile); //false
                console.log(directory.isDirectory); //true
                console.log(directory.name); // "newDirectory"
                console.log(directory.fullPath); // "/parentDirectory/newDirectory"
                console.log(directory.filesystem); // "/"
            }, null);
        }, null);
    }, null);
}, null);

createReader()

Creates a new DirectoryReader to read entries from this directory
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var path = "directory_reader_test",
        options = {create: true, exclusive: false};

    fileSystem.root.getDirectory(path, options, function (directory) {
        var directoryReader = directory.createReader();
        // use directoryReader here
    }, null);
}, null);

getDirectory(path, options, successCallback, errorCallback)

getDirectory Creates or looks up a directory
Parameters:
Name Type Description
path string Either a relative or absolute path from this directory in which to look up or create a directory
options Flags Options to create or exclusively create the directory
successCallback function Called with the new entry
errorCallback function Called with a FileError
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var path = "test",
        options = {create: true, exclusive: false};

    fileSystem.root.getDirectory(path, options, function (directory) {
        console.log(directory.isFile); //false
        console.log(directory.isDirectory); //true
        console.log(directory.name); // "test"
        console.log(directory.fullPath); // "/test"
        console.log(directory.filesystem); // "/"
    }, null);
}, null);

getFile(path, options, successCallback, errorCallback)

Creates or looks up a file.
Parameters:
Name Type Description
path string Either a relative or absolute path from this directory in which to look up or create a file
options Flags Options to create or exclusively create the file
successCallback function Called with the new entry
errorCallback function Called with a FileError
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var path = "file.txt",
        options = {create: true, exclusive: false};

    fileSystem.root.getFile(path, options, function (file) {
        console.log(file.isFile); //true
        console.log(file.isDirectory); //false
        console.log(file.name); // "file.txt"
        console.log(file.fullPath); // "/file.txt"
        console.log(file.filesystem); // "/"
    }, null);
}, null);

getMetadata(successCallback, errorCallback)

Look up the metadata of the entry.
Parameters:
Name Type Description
successCallback function Called with a Metadata object
errorCallback function Called with a FileError
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var path = "test",
        options = {create: true, exclusive: false};

    fileSystem.root.getDirectory(path, options, function (directory) {
        directory.getMetadata(function (metadata) {
            console.log(metadata.modificationTime);
            console.log(metadata.size);
        }, null);
    }, null);
}, null);

getParent(successCallback, errorCallback)

Look up the parent GDDirectoryEntry of this entry.
Parameters:
Name Type Description
successCallback function Called with the parent GDDirectoryEntry object
errorCallback function Called with a FileError
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var options = {create: true, exclusive: false};

    fileSystem.root.getDirectory("parentDirectory", options, function (parentDirectory) {
        // "/parentDirectory" is created here
        fileSystem.root.getDirectory("parentDirectory/nestedDirectory", options, function (nestedDirectory) {
            // "/nestedDirectory" is created here
            nestedDirectory.getParent(function (directory) {
                console.log(directory.isFile); //false
                console.log(directory.isDirectory); //true
                console.log(directory.name); // "parentDirectory"
                console.log(directory.fullPath); // "/parentDirectory"
                console.log(directory.filesystem); // "/"
            }, null);
        }, null);
    }, null);
}, null);

moveTo(parent, newName, successCallback, errorCallback)

Move a file or directory to a new location.
Parameters:
Name Type Description
parent GDDirectoryEntry The directory to which to move this entry
newName string New name of the entry, defaults to the current name
successCallback function Called with the new DirectoryEntry object
errorCallback function Called with a FileError
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var options = {create: true, exclusive: false};

    fileSystem.root.getDirectory("parentDirectory", options, function (parentDirectory) {
        // "/parentDirectory" is created here
        fileSystem.root.getDirectory("nestedDirectory", options, function (nestedDirectory) {
            // "/nestedDirectory" is created here
            nestedDirectory.moveTo(parentDirectory, "newDirectory", function (directory) {
                // now "/nestedDirectory" was moved to "/parentDirectory" with new name "newDirectory"
                console.log(directory.isFile); //false
                console.log(directory.isDirectory); //true
                console.log(directory.name); // "newDirectory"
                console.log(directory.fullPath); // "/parentDirectory/newDirectory"
                console.log(directory.filesystem); // "/"
            }, null);
        }, null);
    }, null);
}, null);

remove(successCallback, errorCallback)

Remove a file or directory. It is an error to attempt to delete a directory that is not empty. It is an error to attempt to delete a root directory of a file system.
Parameters:
Name Type Description
successCallback function Called with no parameters
errorCallback function Called with a FileError
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var path = "test",
        options = {create: true, exclusive: false};

    fileSystem.root.getDirectory(path, options, function (directory) {
        directory.remove();
    }, null);
}, null);

removeRecursively(successCallback, errorCallback)

Deletes a directory and all of it's contents
Parameters:
Name Type Description
successCallback function Called with no parameters
errorCallback function Called with a FileError
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var path = "root_dir",
        options = {create: true, exclusive: false};

    fileSystem.root.getDirectory(path, options, function (directory) {
        fileSystem.root.getFile("root_dir/file.txt", options, function (file) {
             // file is available at path "/root_dir/file.txt"
             // removing "root_dir"
             directory.removeRecursively(function(){
                 // here we have empty file system
             }, null);
        }, null);
    }, null);
}, null);

toURL()

Return a URL that can be used to identify this entry.
Source:
Example
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
    var path = "test",
        options = {create: true, exclusive: false};

    fileSystem.root.getDirectory(path, options, function (directory) {
        console.log(directory.toURL()); // "/test"
    }, null);
}, null);