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. It is defined in the W3C Directories and Systems specification.
NOTE: The following attributes are defined by the W3C specification, but are not supported by Cordova:
The following methods can be invoked on a DirectoryEntry object:
Look up metadata about a directory.
Parameters:
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. Only works on iOS currently - 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
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. It is an error to attempt to:
In addition, an attempt to move a directory on top of an existing empty directory must attempt to delete and replace that directory.
Parameters:
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. It is an error to attempt to:
Directory copies are always recursive - that is, they copy all contents of the directory.
Parameters:
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. It is an error to attempt to:
Parameters:
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:
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. It is an error to attempt to:
Parameters:
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. It is an error to attempt to:
Parameters:
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 (e.g. trying to delete a directory that contains a file that cannot be removed), some of the contents of the directory may be deleted. It is an error to attempt to:
Parameters:
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: insure temporary directories are cleaned manually, or by the application before reinstall
solution: disconnect usb cable from device and run again