Forums > Javascript

javascript filetype "fold"

February 23, 2006 | 10:27 pm

hello,
i learned from the js example "jsfolderiter.js" that a File object’s type would be "fold" if the file is a directory. However, i’m finding that i get a blank filetype for folders. I’m also noticing that .xml files return a blank filetype where as according to "max-fileformats.txt" they should return TEXT.

js is attached.
please put some .txt, a .pat, and/or a .xml in your root folder to test it out.

patch is below.

thanks,

ali

max v2;
#N vpatcher 40 104 640 504;
#P window setfont "Sans Serif" 9.;
#P number 164 60 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 165 90 54 196617 getfile $1;
#P message 60 86 84 196617 foldercontents /;
#P newex 84 175 105 196617 js js-filetype-fold.js;
#P connect 1 0 0 0;
#P connect 2 0 0 0;
#P connect 3 0 2 0;
#P pop;


February 23, 2006 | 11:36 pm

No js was provided. As always, please also provide detailed system
and max versions, and specific usage with any report.

-Joshua


February 23, 2006 | 11:42 pm

weird, i’m using the web-interface for the forum and was pressing on "upload file" after choosing the file.
perhaps that’s not the thing to do.. let’s try again.

max 4.5.6, os x 10.4.5

just in case, here’s the js:

____________

var filelist = new Array();

function foldercontents(mypath)
{
//post(mypath,"n");
var myfolder = new Folder(mypath);
// myfolder.reset();
filelist = new Array();
var counter = 0;
while (!myfolder.end) {
post(myfolder.filename);
post();
filelist[counter]= new File(myfolder.filename);
var thisfile = new File(myfolder.filename);
post("file type is: ",thisfile.filetype);
post();
counter = counter + 1;
myfolder.next();
}
myfolder.close();
}

function getfile(n)
{
post("file name: ",filelist[n].filename);
post();
post("file type: ",filelist[n].filetype);
post();
post("folder path: ",filelist[n].foldername);
post();

}


February 24, 2006 | 12:02 am

On Feb 23, 2006, at 3:42 PM, Ali Momeni wrote:

> weird, i’m using the web-interface for the forum and was pressing
> on "upload file" after choosing the file.
> perhaps that’s not the thing to do.. let’s try again.

Okay. Please note that you’re not following the jsfolderiter
example,l which clearly demostrates that the filetype tested is an
attribute of the *Folder* object rather than the *File* object. I
believe this should solve your problems. You cannot open a folder as
a file.

In general, I would recommend whenever you have a problem like this,
scrutinizing the differences between the working example and your
file. C’mon Ali, I know you can spend a little more time before
getting us involved. :)

-Joshua


February 24, 2006 | 1:05 am

i understand. thanks.

a small followup question,
if i pass an object (of class File or a Folder, i.e. created with "new File() or new Folder()") to a function, how can i test in that function to see if the passed object is a File or a Folder?

a


February 24, 2006 | 1:15 am

On Feb 23, 2006, at 5:05 PM, Ali Momeni wrote:

> a small followup question,
> if i pass an object (of class File or a Folder, i.e. created with
> "new File() or new Folder()") to a function, how can i test in that
> function to see if the passed object is a File or a Folder?

Check out the object.isPrototypeOf() method:

http://developer.mozilla.org/en/docs/
Core_JavaScript_1.5_Reference:Global_Objects:Object:isProtot ypeOf

-Joshua


Viewing 6 posts - 1 through 6 (of 6 total)