license: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This object represents a directory on a file system, as defined by the W3C Directories and Systems specification.
DirectoryEntry
, excluding the path leading to it. (DOMString)DirectoryEntry
. (DOMString)NOTE: The following attribute is defined by the W3C specification, but is not supported:
DirectoryEntry
resides. (FileSystem)The following methods can be invoked on a DirectoryEntry
object:
DirectoryReader
that can read entries from a directory.Look up metadata about a directory.
Parameters:
Metadata
object. (Function)Metadata
. Invoked with a FileError
object. (Function)Quick Example
function success(metadata) { console.log("Last Modified: " + metadata.modificationTime); } function fail(error) { alert(error.code); } // Request the metadata object for this entry entry.getMetadata(success, fail);
Set metadata on a directory. Currently works only on iOS. - this will set the extended attributes of a directory.
Parameters:
Quick Example
function success() { console.log("The metadata was successfully set."); } function fail() { alert("There was an error in setting the metadata"); } // Set the metadata entry.setMetadata(success, fail, { "com.apple.MobileBackup": 1});
iOS Quirk
com.apple.MobileBackup
extended attribute is supported. Set the value to 1
to prevent the directory from being backed up to iCloud. Set the value to 0
to re-enable the directory to be backed up to iCloud.Quick Example
function setFolderMetadata(localFileSystem, subFolder, metadataKey, metadataValue) { var onSetMetadataWin = function() { console.log("success setting metadata") } var onSetMetadataFail = function() { console.log("error setting metadata") } var onGetDirectoryWin = function(parent) { var data = {}; data[metadataKey] = metadataValue; parent.setMetadata(onSetMetadataWin, onSetMetadataFail, data); } var onGetDirectoryFail = function() { console.log("error getting dir") } var onFSWin = function(fileSystem) { fileSystem.root.getDirectory(subFolder, {create: true, exclusive: false}, onGetDirectoryWin, onGetDirectoryFail); } var onFSFail = function(evt) { console.log(evt.target.error.code); } window.requestFileSystem(localFileSystem, 0, onFSWin, onFSFail); } setFolderMetadata(LocalFileSystem.PERSISTENT, "Backups", "com.apple.MobileBackup", 1);
Move a directory to a different location on the file system. An error results if the app attempts to:
Moving a directory on top of an existing empty directory attempts to delete and replace that directory.
Parameters:
DirectoryEntry
object for the new directory. (Function)FileError
object. (Function)Quick Example
function success(entry) { console.log("New Path: " + entry.fullPath); } function fail(error) { alert(error.code); } function moveDir(entry) { var parent = document.getElementById('parent').value, parentName = parent.substring(parent.lastIndexOf('/')+1), newName = document.getElementById('newName').value, parentEntry = new DirectoryEntry(parentName, parent); // move the directory to a new directory and rename it entry.moveTo(parentEntry, newName, success, fail); }
Copy a directory to a different location on the file system. An error results if the app attempts to:
Directory copies are always recursive, and copy all contents of the directory.
Parameters:
DirectoryEntry
object for the new directory. (Function)FileError
object. (Function)Quick Example
function win(entry) { console.log("New Path: " + entry.fullPath); } function fail(error) { alert(error.code); } function copyDir(entry) { var parent = document.getElementById('parent').value, parentName = parent.substring(parent.lastIndexOf('/')+1), newName = document.getElementById('newName').value, parentEntry = new DirectoryEntry(parentName, parent); // copy the directory to a new directory and rename it entry.copyTo(parentEntry, newName, success, fail); }
Returns a URL that can be used to locate the directory.
Quick Example
// Get the URL for this directory var dirURL = entry.toURL(); console.log(dirURL);
Deletes a directory. An error results if the app attempts to:
Parameters:
FileError
object. (Function)Quick Example
function success(entry) { console.log("Removal succeeded"); } function fail(error) { alert('Error removing directory: ' + error.code); } // remove this directory entry.remove(success, fail);
Look up the parent DirectoryEntry
containing the directory.
Parameters:
DirectoryEntry
. (Function)DirectoryEntry
. Invoked with a FileError
object. (Function)Quick Example
function success(parent) { console.log("Parent Name: " + parent.name); } function fail(error) { alert('Failed to get parent directory: ' + error.code); } // Get the parent DirectoryEntry entry.getParent(success, fail);
Creates a new DirectoryReader to read entries in a directory.
Quick Example
// create a directory reader var directoryReader = entry.createReader();
Creates or looks up an existing directory. An error results if the app attempts to:
Parameters:
DirectoryEntry
. (DOMString)DirectoryEntry
object. (Function)FileError
object. (Function)Quick Example
function success(parent) { console.log("Parent Name: " + parent.name); } function fail(error) { alert("Unable to create new directory: " + error.code); } // Retrieve an existing directory, or create it if it does not already exist entry.getDirectory("newDir", {create: true, exclusive: false}, success, fail);
Creates or looks up a file. An error results if the app attempts to:
Parameters:
DirectoryEntry
. (DOMString)FileEntry
object. (Function)FileError
object. (Function)Quick Example
function success(parent) { console.log("Parent Name: " + parent.name); } function fail(error) { alert("Failed to retrieve file: " + error.code); } // Retrieve an existing file, or create it if it does not exist entry.getFile("newFile.txt", {create: true, exclusive: false}, success, fail);
Deletes a directory and all of its contents. In the event of an error (such as trying to delete a directory containing a file that cannot be removed), some of the contents of the directory may be deleted. An error results if the app attempts to:
Parameters:
DirectoryEntry
has been deleted. Invoked with no parameters. (Function)DirectoryEntry
. Invoked with a FileError
object. (Function)Quick Example
function success(parent) { console.log("Remove Recursively Succeeded"); } function fail(error) { alert("Failed to remove directory or it's contents: " + error.code); } // remove the directory and all it's contents entry.removeRecursively(success, fail);
May fail with a ControlledAccessException
in the following cases:
Solution: ensure temporary directories are cleaned manually, or by the application prior to reinstallation.
Solution: disconnect the USB cable from the device and run again.