DirectoryReader Interface
Estimated reading time: 2 minutes
The DirectoryReader
interface offers methods concerned with referring information of files and directories under the '/media'
directory of a USB storage.
Attributes
-
DOMString result
result
is the result of directory entries in JSON format.
Methods
-
void getTree()
getTree()
method starts directory traversal at the specified path asynchronously. When the operation is finished, the result attribute is updated and the function assigned toonload
is called. Or,onerror
is called when the operation failed. The result is in JSON format that contains an array of nodes. Symbolic links are not followed. -
void abort()
abort()
method cancels the request on the object. Then,onabort
is called. -
void readEntries(EntryCallback callback)
readEntries()
method returns directory entries one by one through the callback function. When it reaches the end of the directory entries, the callback function is called withnull
andonload
is called. If theabort()
method is called, directory reading is stopped immediately andonabort
is called.
Events
- onload
- onabort
- onerror
Example
- Define the
onload
callback and show the resultvar reader = new sony.tv.DirectoryReader('/media'); reader.onload = function() { var json = JSON.parse(reader.result); for (var i = 0; i < json.length; i++) { console.log(json[i].name); } };
- Result example
If the target directory contains the following,onload
is called with the following result in JSON format.- Included files:
- readme.txt (file)
- LICENSE (file)
- src (directory with sub entries)
- main.c (file)
- plugins (empty directory)
- Result
[ { "name": "readme.txt", "size": 1234, "date": "Wed, 28 May 2014 17:00:00 GMT" }, { "name": "LICENSE", "size": 5678, "date": "Wed, 28 May 2014 17:00:00 GMT" }, { "name": "src", "date": "Wed, 28 May 2014 17:00:00 GMT", "children": [ { "name": "main.c", "size": 321, "date": "Wed, 28 May 2014 17:00:00 GMT" } { "name": "plugins", "date": "Wed, 28 May 2014 17:00:00 GMT", "children": [], "items": [] } ] } ]
- Included files: