언어 설정

Menu
Sites
Language
Create folder and file

i want to cr8 folder and inside that folder 1 txt file . then i want to read string from that txt and append new data to last

 

 i am getting 'undefined' is not a function (evaluating 'dir.createDirectory("newDir")')

Edited by: appdaily on 25 3월, 2015

Responses

11 댓글
AVSukhov

Hello,

In what directory you are trying to create your own directory (dir object)?

 

appdaily

any where i am ok

AVSukhov

Hello,

F.e. create new dir with file under "documents" virtula root ("opt/usr/media/Documents"):

var newDir, newFile;
    tizen.filesystem.resolve("documents", function(dir) 
            {
               newDir = dir.createDirectory("newDir");
               newFile = newDir.createFile("newFilePath.txt");
               newFile.openStream(
                         "w",
            	         function(fs) {
            	           fs.write("test test test");
            	           fs.close();
            	         }, function(e) {
            	           console.log("Error " + e.message);
            	         }, "UTF-8");
            });

 

appdaily

how i can read that file data from 2nd html file

AVSukhov

Hello,

You can use following code:

tizen.filesystem.resolve("documents", function(dir) 
            {
              
               file = dir.resolve("newDir/newFilePath.txt");
    	       file.openStream(
    	    		   "r", 
    	    		   function(fs) {
            	           var text = fs.read(file.fileSize);
            	           fs.close();
            	           alert(text);
            	         }, function(e) {
            	           console.log("Error " + e.message);
            	         }, "UTF-8");
            });

 

appdaily

i am getting  node already exists . how i can check  file exit or not

 newFile = newDir.createFile("newFilePath.txt");
AVSukhov

Hello,

You can before create file verify is file exist using resolve() method.

If resolve return NotFoundError, you can create file.

appdaily

hey i have make one fuction

function httpcall() {
        var title = "";
        db.transaction(function(t) {
            t.executeSql("SELECT * FROM tizenTable WHERE id=?", [ 1 ],
                    function(tran, r) {
                        for (var i = 0; i < r.rows.length; i++) {

                            title = r.rows.item(i).title;
                            console.log("title" + title);
                            return title;
                        }
                    }, function(t, e) {
                        alert("Error:" + e.message);
                    });
        });
        
        
    }

var s = httpcall();

if(s == "value")

 

 

but pormblem is its not wating to get httpcall reposne its doing in backgroud and doing to next step thats my if conditions alwaus fasle any way we can stop till i get reutrn from function

AVSukhov

Hello,

In this case, you can try jQuery promise or jQuery deffered object:

http://api.jquery.com/promise/

http://api.jquery.com/category/deferred-object/

Or you can search another way to synchronization function calls.

appdaily

can we create own app folder and invisable ? snippet if possible

AVSukhov

Hello,

You can create directory under "wgt-private" virtual root directory:

  • wgt-private - the location for a widget's private storage          
    var newDir, newFile;
    tizen.filesystem.resolve("wgt-private", function(dir) 
            {
    	newDir = dir.createDirectory("newDir");
               newFile = newDir.createFile("newFile.txt");
               newFile.openStream(
            	         "w",
            	         function(fs) {
            	           fs.write("test test test");
            	           fs.close();
            	         }, function(e) {
            	           console.log("Error " + e.message);
            	         }, "UTF-8");
            });