Class: GDFileEntry

GDFileEntry()

An interface representing a directory on the file system.

Constructor

new GDFileEntry()

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.getFile("file.txt", options, function (nestedFile) {
            // "/file.txt" is created here
            nestedFile.copyTo(parentDirectory, "renamedFile.txt", function (file) {
                // now "/file.txt" was copied to "/parentDirectory" with new name "/renamedFile.txt"
                console.log(file.isFile); //true
                console.log(file.isDirectory); //false
                console.log(file.name); // "renamedFile.txt"
                console.log(file.fullPath); // "/parentDirectory/renamedFile.txt"
                console.log(file.filesystem); // "/"
            }, null);
        }, null);
    }, null);
}, null);

createWriter(successCallback, errorCallback)

Parameters:
Name Type Description
successCallback function Called with the new FileWriter
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) {
        file.createWriter(function (writer) {
            // here GDFileWriter methods such as writer.write(), writer.seek() and writer.truncate() are available
        });
    }, null);
}, null);

file(successCallback, errorCallback)

Returns a File that represents the current state of the file that this FileEntry represents.
Parameters:
Name Type Description
successCallback function Called with the new File object
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); // "/"

        file.file(function (file) {
            console.log(file.name); // "file.txt"
            console.log(file.fullPath); // "/file.txt"
            console.log(file.lastModifiedDate);
            console.log(file.size);
            console.log(file.type);
        }, null);
    }, 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 = "file.txt",
        options = {create: true, exclusive: false};

    fileSystem.root.getFile(path, options, function (file) {
        file.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.getFile("parentDirectory/nestedFile.txt", options, function (nestedFile) {
            // "/nestedFile.txt" is created here
            nestedFile.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.getFile("file.txt", options, function (nestedFile) {
            // "/file.txt" is created here
            nestedFile.moveTo(parentDirectory, "renamedFile.txt", function (file) {
                // now "/file.txt" was moved to "/parentDirectory" with new name "/renamedFile.txt"
                console.log(file.isFile); //true
                console.log(file.isDirectory); //false
                console.log(file.name); // "renamedFile.txt"
                console.log(file.fullPath); // "/parentDirectory/renamedFile.txt"
                console.log(file.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 = "file.txt",
        options = {create: true, exclusive: false};

    fileSystem.root.getFile(path, options, function (file) {
        file.remove();
    }, null);
}, null);

toURL()

Return a URL that can be used to identify this entry.
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.toURL()); // "/file.txt"
    }, null);
}, null);