DirectoryReader Interface
Estimated reading time: 1 minute
这个 DirectoryReader
接口提供与引用文件和目录信息相关的方法下 '/media'
USB存储器的目录。
属性
-
readonly
属性的结果JSON格式的目录项的结果。
方法
-
void getTree()
The
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()
The
abort()
method cancels the request on the object. Then,onabort
is called. -
void readEntries(EntryCallback callback)
The
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.
事件
- onload
- onabort
- onerror
举例说明
- 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); } };
- 结果示例 如果目标目录包含以下内容,
onload
以JSON格式调用,结果如下。- Included files:
- readme.txt (file)
- LICENSE (file)
- src (directory with sub entries)
- main.c (file)
- plugins (empty directory)
- 结果
[ { "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: