Class Storage#listFiles
storage
- Defined in: storage.js
| Constructor Attributes | Constructor Name and Description |
|---|---|
|
Storage#listFiles(successCallback, errorCallback, options)
Lists files in a directory stored in external or internal memory. |
Class Detail
Storage#listFiles(successCallback, errorCallback, options)
Lists files in a directory stored in external or internal memory. Directory location is in URI format. Listing a directory beyond the application root path is not allowed.
function listFiles() {
var successCb = function (cbObject){
var files = cbObject.files;
for(var i = 0 ; i < files.length; ++i){
var fileInfo = files[i];
console.log("File Name: " + fileInfo.name);
console.log("File Type: " + fileInfo.type);
console.log("File Size: " + fileInfo.size);
}
};
var failureCb = function(cbObject){
var errorCode = cbObject.errorCode;
var errorText = cbObject.errorText;
console.log( " Error Code [" + errorCode + "]: " + errorText);
};
// List files in the internal memory
var listOption = {
path: "file://internal/list/this/dir"
};
var storage = new Storage();
storage.listFiles(successCb, failureCb, listOption);
// List files in the mass storage device in USB port 1.
var listOption = {
path: "file://usb:1/list/this/dir"
};
storage.listFiles(successCb, failureCb, listOption);
}
- Parameters:
- {Function} successCallback
- success callback function.
- {Function} errorCallback
- failure callback function.
- {Object} options
Property Type Description Required path Storage.SCAP_URI URI to the directory to look for. required
- Since:
- 1.0, 1.1 list a directory
- Returns:
After the method is successfully executed, successCallback is called with total count and an array of file info, which contains a list of File Info Object. '.' and '..' will not be included in the list.
Property Type Description totalCount Number Number of items files Array List of files in the directory. File Info has following properties. files.name String Name of the file files.type String Type of the file files.size Number Size of the File If an error occurs, errorCallback is called with errorCode and errorText. To see how error codes are defined, check Error.ERROR_CODE