error in Directory creation

929 views
Skip to first unread message

Pab .Net

unread,
Aug 4, 2011, 2:46:27 AM8/4/11
to phonegap
hi,

i used the following code to create a directory


function success(parent) {
console.log("Parent Name: " + parent.name);
}

function fail(error) {
alert("Unable to create new directory: " + error.code);
}
function create() {
// Retrieve an existing directory, or create it if it does not already
exist
entry.getDirectory("PHOTODIR", {create: true, exclusive: false},
success, fail);
}

following error occurs
ReferenceError: Can't find variable: entry at file:///android_asset/www/dir.js:15


could any one provide me solution pls?

thanks
-pab

Wilin

unread,
Aug 4, 2011, 3:40:38 AM8/4/11
to phonegap
You have to get a directoryentry (the variable entry in the examples)
first. This can be done in two ways:
way 1: getLocalFileSystem

function onSuccess(fileSystem) {
var entry=fileSystem.root;
}

// request the persistent file system
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess,
onError);

or way 2: resolveLocalFileSystemURI

function onSuccess(directryEntry) {
var entry = directoryEntry;
}

window.resolveLocalFileSystemURI("file:///sdcard", onSuccess,
onError);

Viras

unread,
Aug 4, 2011, 4:07:47 AM8/4/11
to phon...@googlegroups.com
Please use getLocalFileSystem as this is the more portable way (and
should work on any platform PhoneGap supports).

The resolveLocalFileSystemURI should be used with caution and only if
you know what you are doing - since the path is not platform independent!

Best,
Viras

--
GOFG - Get On Fat Guy
http://www.gofg.at/ - powered by PhoneGap

Pab .Net

unread,
Aug 4, 2011, 6:00:49 AM8/4/11
to phonegap
Hi,


thanks for reply, but i need to know how to create a directory in
sdcrad,
so provide me idea regarding that


thanks,
-pab

Viras

unread,
Aug 4, 2011, 11:57:49 AM8/4/11
to phon...@googlegroups.com
Well, on Android, if you use requestFileSystem with
LocalFileSystem.PERSISTENT you get the sdcard root folder. From that
starting point on you can start creating a directory, with the
getDirectory function of the root entry.

See http://docs.phonegap.com/phonegap_file_file.md.html for details.

Best,
Wolfgang

--

Pab .Net

unread,
Aug 5, 2011, 3:12:04 AM8/5/11
to phonegap
Hi Viras,


Thanks for you idea, it works now, i also needed to know how
create directory automatically when my application is installed in
device

thanks,
-pab

Viras

unread,
Aug 5, 2011, 12:54:11 PM8/5/11
to phon...@googlegroups.com
Hi pab,

I think this is device (OS) dependent. Creating a directory during
install is definitely something you have to check for each platform on
its own (and not with PhoneGap).

Best,
Viras

--

Pab .Net

unread,
Aug 8, 2011, 9:22:11 AM8/8/11
to phonegap
Hi Viras,


Thanks for ur reply,..


thanks,
-pab

Reply all
Reply to author
Forward
0 new messages