[File] add directory and entry tutorials and guides
authorLukasz Bardeli <l.bardeli@samsung.com>
Fri, 13 May 2016 13:27:31 +0000 (15:27 +0200)
committerLukasz Bardeli <l.bardeli@samsung.com>
Tue, 28 Jun 2016 08:24:21 +0000 (10:24 +0200)
Change-Id: Ic9929c0b3e8282b48fccae3bd144c4006e9d4ac8
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
org.tizen.guides/html/web/tizen/cordova/file_w.htm
org.tizen.tutorials/html/web/tizen/cordova/file_tutorial_w.htm

index 9bfbfea..5feb6c0 100644 (file)
@@ -78,12 +78,22 @@ See the <a href="../../../../../org.tizen.tutorials/html/web/tizen/cordova/file_
 <!-------------------------------------------------- directories -------------------------------------------------->
 <h2 id="directories">Directories operations</h2>
 <p>
-Some description
+Thanks directories operation you can create or remove directory or file, read all entries from specific directory.
 
 See the <a href="../../../../../org.tizen.tutorials/html/web/tizen/cordova/file_tutorial_w.htm#directories">example</a>.
 </p>
 <!-------------------------------------------------- directories -------------------------------------------------->
 
+<!-------------------------------------------------- entries -------------------------------------------------->
+<h2 id="entries">Entries operations</h2>
+<p>
+Thanks entries operation you can get Medadata, move, copy remove entries, also you can look up the parent DirectoryEntry containing this Entry or return URL this entry.
+
+See the <a href="../../../../../org.tizen.tutorials/html/web/tizen/cordova/file_tutorial_w.htm#entries">example</a>.
+</p>
+<!-------------------------------------------------- entries -------------------------------------------------->
+
+
 <!-------------------------------------------------- files -------------------------------------------------->
 <h2 id="files">Files operations</h2>
 <p>
index 89e201b..82c0884 100644 (file)
@@ -109,20 +109,233 @@ The output:
 
 <!-------------------------------------------------- directories -------------------------------------------------->
 <h2 id="directories">Directories operations</h2>
+<ol>
+<li>
+<p>
+To create directory you can use <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/cordova/file.html#DirectoryEntry::getDirectory"><i>getDirectory</i></a> method.
+</p>
+<pre class="prettyprint">
+requestFileSystem(TEMPORARY, 100, function(fs) {
+ fs.root.getDirectory("ert",{create:true},function(dir){
+     console.log('Created dir: '+dir.name);
+  })
+});
+</pre>
 <p>
-Description.
+The output:
 </p>
 <pre class="prettyprint">
-//////////////////// some code
+Created dir: ert
+</pre>
+If options is <em>{create:false}</em> or <em>null</em> entry of existing directory will be return in successCallback.
+</li>
+
+<li>
+In a similar way, you can create a file. To achieve that you can use  <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/cordova/file.html#DirectoryEntry::getFile"><i>getFile</i></a> method.
+Also if options is <em>{create:false}</em> or <em>null</em> entry of existing file will be return in successCallback.
+<pre class="prettyprint">
+requestFileSystem(TEMPORARY, 100, function(fs) {
+ fs.root.getFile("qa.txt",{create:true},function(file){
+       console.log('Created file: '+file.name);
+ });
+});
+</pre>
+<p>
+The output:
+</p>
+<pre class="prettyprint">
+Created file: qa.txt
+</pre>
+</li>
+
+<li>
+To achieve delete a directory and all of its contents, you can use <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/cordova/file.html#DirectoryEntry::removeRecursively"><i>removeRecursively</i></a> method.
+<pre class="prettyprint">
+requestFileSystem(TEMPORARY, 100, function(fs) {
+ fs.root.getDirectory("testDirectory", {create:true},
+   function(directoryEntry) {
+     directoryEntry.removeRecursively(function() {
+       console.log("success");
+     });
+ });
+});
+</pre>
+<p>
+The output:
+</p>
+<pre class="prettyprint">
+success
+</pre>
+</li>
+
+<li>
+To read entries you have to create reader first, you can use <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/cordova/file.html#DirectoryEntry::createReader"><i>createReader</i></a> method.
+<pre class="prettyprint">
+requestFileSystem(TEMPORARY, 100, function (entry) {
+ entry.root.getDirectory("MyDocument", {create:true}, function(dirEntry) {
+      var directoryReader = dirEntry.createReader();
+  });
+});
+</pre>
+</li>
+
+<li>
+Having directoryReader you can read the next block of entries from this directory.Please use <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/cordova/file.html#DirectoryReader::readEntries"><i>readEntries</i></a> method.
+<pre class="prettyprint">
+requestFileSystem(TEMPORARY, 100, function(fs) {
+ var a = fs.root.createReader();
+ a.readEntries(function successCallback(entries) {
+   console.log("success");
+ });
+});
 </pre>
 <p>
 The output:
 </p>
 <pre class="prettyprint">
-///////////////// some output
+success
 </pre>
+</li>
+
+</ol>
 <!-------------------------------------------------- directories -------------------------------------------------->
 
+<!-------------------------------------------------- entries -------------------------------------------------->
+<h2 id="entries">Entries operations</h2>
+<ol>
+<li>
+<p>
+To look up metadata about entry, you can use <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/cordova/file.html#Entry::getMetadata"><i>getMetadata</i></a> method.
+</p>
+<pre class="prettyprint">
+requestFileSystem(TEMPORARY, 100, function(fs) {
+ fs.root.getMetadata(function (metadata) {
+   console.log("Last modification time: " + metadata.modificationTime);// get metadata successfully
+ });
+});
+</pre>
+<p>
+The output:
+</p>
+<pre class="prettyprint">
+Last modification time: Fri Jan 02 2015 03:58:08 GMT+0900 (KST)
+</pre>
+</li>
+
+<li>
+<p>
+To move an entry to a different location on the file system, you can use <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/cordova/file.html#Entry::moveTo"><i>moveTo</i></a> method.
+</p>
+<pre class="prettyprint">
+successCallback = function(entry){console.log('Full path to the moved file: '+entry.fullPath)};
+requestFileSystem(TEMPORARY, 100, function(fs) {
+ fs.root.getDirectory('testDirectory', {create:true}, function(direntry) {
+   fs.root.getFile("aa.txt", {create:true}, function(fileentry) {
+     console.log('Full path before move: '+fileentry.fullPath);
+     fileentry.moveTo(direntry,'newname.txt',successCallback);
+   });
+ });
+});
+</pre>
+<p>
+The output:
+</p>
+<pre class="prettyprint">
+Full path before move: /aa.txt
+Full path to the moved file: /testDirectory/newname.txt
+</pre>
+</li>
+
+<li>
+<p>
+To copy an entry to a different location on the file system, you can use <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/cordova/file.html#Entry::copyTo"><i>copyTo</i></a> method.
+</p>
+<pre class="prettyprint">
+successCallback = function(entry){console.log('Full path to the copied file: '+entry.fullPath);};
+requestFileSystem(TEMPORARY, 100, function(fs) {
+ fs.root.getDirectory('testDirectory', {create:true},
+   function(direntry) {
+     fs.root.getFile("test.txt", {create:true},
+       function(fileentry) {
+         fileentry.copyTo(direntry,'newname.txt',successCallback);
+       }
+   );
+ });
+});
+</pre>
+<p>
+The output:
+</p>
+<pre class="prettyprint">
+Full path to the copied file: /testDirectory/newname.txt
+</pre>
+</li>
+
+<li>
+<p>
+To look up the parent DirectoryEntry containing this Entry, you can use <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/cordova/file.html#Entry::getParent "><i>getParent </i></a> method. If this Entry is the root of its filesystem, its parent is itself. 
+</p>
+<pre class="prettyprint">
+requestFileSystem(TEMPORARY, 100, function(fs) {
+ fs.root.getParent(function (entry) {
+   console.log("success");
+ });
+});
+</pre>
+<p>
+The output:
+</p>
+<pre class="prettyprint">
+success
+</pre>
+</li>
+
+<li>
+<p>
+To deletes a file or directory, you can use <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/cordova/file.html#Entry::remove"><i> remove </i></a> method. It is an error to attempt to delete a directory that is not empty. It is an error to attempt to delete the root directory of a filesystem.
+</p>
+<pre class="prettyprint">
+requestFileSystem(TEMPORARY, 100, function(fs) {
+ fs.root.getFile('test.txt', {create: true}, function(fileEntry) {
+   fileEntry.remove(function () {
+     console.log("success");
+   });
+ });
+});
+</pre>
+<p>
+The output:
+</p>
+<pre class="prettyprint">
+success
+</pre>
+</li>
+
+<li>
+<p>
+To return a URL that can be used to identify this entry, you can use <a href="../../../../../org.tizen.web.apireference/html/device_api/mobile/tizen/cordova/file.html#Entry::toURL"><i>toURL</i></a> method.
+</p>
+<pre class="prettyprint">
+requestFileSystem(TEMPORARY, 100, function(fs) {
+ fs.root.getDirectory('testDirectory', {create:true},
+   function(entry) {
+     var url = entry.toURL();
+     console.log('URL: '+url);
+ });
+});
+</pre>
+<p>
+The output:
+</p>
+<pre class="prettyprint">
+URL: file:///home/owner/apps_rw/WfigBlWDyf/tmp/testDirectory/
+</pre>
+</li>
+
+</ol>
+<!-------------------------------------------------- entries -------------------------------------------------->
+
+
 <!-------------------------------------------------- files -------------------------------------------------->
 <h2 id="files">Files operations</h2>
 <p>