How to create folder on root of sdcard (working on Android + iPhone)?

2,827 views
Skip to first unread message

Jiri

unread,
Aug 23, 2011, 1:46:40 PM8/23/11
to phonegap
Hello,
I would like to to create folder on root of sdcard (working on Android
+ iPhone), i tried use phonegap Documentation but i cannot do it
correctly.

What is easient and multiplatform way?

I tried for example this:

function createDir(dirname){
var fman = new FileMgr();
fman.createDirectory(""+dirname,onSuccess(),fail);
}

But this not working.

Thanks

Pab .Net

unread,
Aug 24, 2011, 9:33:16 AM8/24/11
to phonegap

Jiri

unread,
Aug 25, 2011, 4:34:36 AM8/25/11
to phonegap
Thanks, but it seems like NOT multiplatform solution.

On 24 srp, 15:33, "Pab .Net" <prabu.ne...@gmail.com> wrote:
> try this
>
> http://groups.google.com/group/phonegap/browse_thread/thread/c0a8aa11...
>
> -pab

Simon MacDonald

unread,
Aug 25, 2011, 11:15:55 AM8/25/11
to phon...@googlegroups.com
This is the cross platform way to do it.

function createDir(dirname){
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function(fileSys) {
fileSys.root.getDirectory(dirname, {create: true,
exclusive: false},
function(directory) {
console.log("Directory has been created");
}, createError);
}, createError);
}

function createError(error){
alert(error.code);
}

Simon Mac Donald
http://hi.im/simonmacdonald

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com
>

Message has been deleted

Jiri

unread,
Aug 31, 2011, 1:01:29 PM8/31/11
to phonegap
Thanks, now it works!
But im little out from this:

What exactly means "entry" in Phonegap and how i create instance from
entry?

I try to find in Phonegap API docs, but without success.

function moveFile(entry) {
var parent = document.getElementById('parent').value,
parentEntry = new DirectoryEntry({fullPath: parent});

// move the file to a new directory and rename it
entry.moveTo(parentEntry, "newFile.txt", success, fail);
}

On Aug 25, 5:15 pm, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> This is the cross platform way to do it.
>
> function createDir(dirname){
>     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
>             function(fileSys) {
>                 fileSys.root.getDirectory(dirname, {create: true,
> exclusive: false},
>                     function(directory) {
>                         console.log("Directory has been created");
>                     }, createError);
>             }, createError);
>
> }
>
> function createError(error){
>        alert(error.code);
>
> }
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald

Simon MacDonald

unread,
Aug 31, 2011, 2:23:45 PM8/31/11
to phon...@googlegroups.com
In this case entry is an instance of FileEntry or DirectoryEntry. You can read up on them in the file section of docs.PhoneGap.com.

Simon
--

Jiri

unread,
Sep 1, 2011, 11:24:11 AM9/1/11
to phonegap
Thanks! Now works perfectly for dirs and files.
Great introduction is also here>
http://www.html5rocks.com/en/tutorials/file/filesystem/

But I still dont know how to write file insite www direcory, stored in
device.

Becasue is possible, that user has not sdcard inside a phone.

Thanks for Your help.

Jiri

unread,
Sep 1, 2011, 11:35:21 AM9/1/11
to phonegap
I tried something like>

function createInnerFile(filename){
window.requestFileSystem(window.PERSISTENT, 0, function(fileSys){
fileSys.root.getFile(filename, {
create: true,
exclusive: false
}, function(directory){
alert("File has been created");
}, createError);
}, createError);
}

But, not working, and dont not throw anny error.

Simon MacDonald

unread,
Sep 2, 2011, 9:51:47 AM9/2/11
to phon...@googlegroups.com
You can't write stuff to the www directory of your app. If you want to
keep data in an application specific directory on Android use
"/sdcard/Android/data/<package name>/cache

Reply all
Reply to author
Forward
0 new messages