From 4cb84a3ccc7bb4300ba35e383769910e619dd6a5 Mon Sep 17 00:00:00 2001 From: Lukasz Bardeli Date: Fri, 13 May 2016 15:27:31 +0200 Subject: [PATCH] [File] add directory and entry tutorials and guides Change-Id: Ic9929c0b3e8282b48fccae3bd144c4006e9d4ac8 Signed-off-by: Lukasz Bardeli --- org.tizen.guides/html/web/tizen/cordova/file_w.htm | 12 +- .../html/web/tizen/cordova/file_tutorial_w.htm | 219 ++++++++++++++++++++- 2 files changed, 227 insertions(+), 4 deletions(-) diff --git a/org.tizen.guides/html/web/tizen/cordova/file_w.htm b/org.tizen.guides/html/web/tizen/cordova/file_w.htm index 9bfbfea..5feb6c0 100644 --- a/org.tizen.guides/html/web/tizen/cordova/file_w.htm +++ b/org.tizen.guides/html/web/tizen/cordova/file_w.htm @@ -78,12 +78,22 @@ See the Directories operations

-Some description +Thanks directories operation you can create or remove directory or file, read all entries from specific directory. See the example.

+ +

Entries operations

+

+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 example. +

+ + +

Files operations

diff --git a/org.tizen.tutorials/html/web/tizen/cordova/file_tutorial_w.htm b/org.tizen.tutorials/html/web/tizen/cordova/file_tutorial_w.htm index 89e201b..82c0884 100644 --- a/org.tizen.tutorials/html/web/tizen/cordova/file_tutorial_w.htm +++ b/org.tizen.tutorials/html/web/tizen/cordova/file_tutorial_w.htm @@ -109,20 +109,233 @@ The output:

Directories operations

+
    +
  1. +

    +To create directory you can use getDirectory method. +

    +
    +requestFileSystem(TEMPORARY, 100, function(fs) {
    + fs.root.getDirectory("ert",{create:true},function(dir){
    +     console.log('Created dir: '+dir.name);
    +  })
    +});
    +

    -Description. +The output:

    -//////////////////// some code
    +Created dir: ert
    +
    +If options is {create:false} or null entry of existing directory will be return in successCallback. +
  2. + +
  3. +In a similar way, you can create a file. To achieve that you can use getFile method. +Also if options is {create:false} or null entry of existing file will be return in successCallback. +
    +requestFileSystem(TEMPORARY, 100, function(fs) {
    + fs.root.getFile("qa.txt",{create:true},function(file){
    +       console.log('Created file: '+file.name);
    + });
    +});
    +
    +

    +The output: +

    +
    +Created file: qa.txt
    +
    +
  4. + +
  5. +To achieve delete a directory and all of its contents, you can use removeRecursively method. +
    +requestFileSystem(TEMPORARY, 100, function(fs) {
    + fs.root.getDirectory("testDirectory", {create:true},
    +   function(directoryEntry) {
    +     directoryEntry.removeRecursively(function() {
    +       console.log("success");
    +     });
    + });
    +});
    +
    +

    +The output: +

    +
    +success
    +
    +
  6. + +
  7. +To read entries you have to create reader first, you can use createReader method. +
    +requestFileSystem(TEMPORARY, 100, function (entry) {
    + entry.root.getDirectory("MyDocument", {create:true}, function(dirEntry) {
    +      var directoryReader = dirEntry.createReader();
    +  });
    +});
    +
    +
  8. + +
  9. +Having directoryReader you can read the next block of entries from this directory.Please use readEntries method. +
    +requestFileSystem(TEMPORARY, 100, function(fs) {
    + var a = fs.root.createReader();
    + a.readEntries(function successCallback(entries) {
    +   console.log("success");
    + });
    +});
     

    The output:

    -///////////////// some output
    +success
     
    +
  10. + +
+ +

Entries operations

+
    +
  1. +

    +To look up metadata about entry, you can use getMetadata method. +

    +
    +requestFileSystem(TEMPORARY, 100, function(fs) {
    + fs.root.getMetadata(function (metadata) {
    +   console.log("Last modification time: " + metadata.modificationTime);// get metadata successfully
    + });
    +});
    +
    +

    +The output: +

    +
    +Last modification time: Fri Jan 02 2015 03:58:08 GMT+0900 (KST)
    +
    +
  2. + +
  3. +

    +To move an entry to a different location on the file system, you can use moveTo method. +

    +
    +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);
    +   });
    + });
    +});
    +
    +

    +The output: +

    +
    +Full path before move: /aa.txt
    +Full path to the moved file: /testDirectory/newname.txt
    +
    +
  4. + +
  5. +

    +To copy an entry to a different location on the file system, you can use copyTo method. +

    +
    +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);
    +       }
    +   );
    + });
    +});
    +
    +

    +The output: +

    +
    +Full path to the copied file: /testDirectory/newname.txt
    +
    +
  6. + +
  7. +

    +To look up the parent DirectoryEntry containing this Entry, you can use getParent method. If this Entry is the root of its filesystem, its parent is itself. +

    +
    +requestFileSystem(TEMPORARY, 100, function(fs) {
    + fs.root.getParent(function (entry) {
    +   console.log("success");
    + });
    +});
    +
    +

    +The output: +

    +
    +success
    +
    +
  8. + +
  9. +

    +To deletes a file or directory, you can use remove 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. +

    +
    +requestFileSystem(TEMPORARY, 100, function(fs) {
    + fs.root.getFile('test.txt', {create: true}, function(fileEntry) {
    +   fileEntry.remove(function () {
    +     console.log("success");
    +   });
    + });
    +});
    +
    +

    +The output: +

    +
    +success
    +
    +
  10. + +
  11. +

    +To return a URL that can be used to identify this entry, you can use toURL method. +

    +
    +requestFileSystem(TEMPORARY, 100, function(fs) {
    + fs.root.getDirectory('testDirectory', {create:true},
    +   function(entry) {
    +     var url = entry.toURL();
    +     console.log('URL: '+url);
    + });
    +});
    +
    +

    +The output: +

    +
    +URL: file:///home/owner/apps_rw/WfigBlWDyf/tmp/testDirectory/
    +
    +
  12. + +
+ + +

Files operations

-- 2.7.4