Forums > Javascript

Folder() and non-existent drives & folders on XP

April 4, 2006 | 10:22 pm

I’m trying to test if a drive is mounted on an XP machine by checking the count of files/folders. I can do it with the "folder" object in Max, but it’s slow. So I started a js that would be simpler and perhaps faster. However, I get strange results when I check the count of, say "D:/" (I don’t have a D:/ drive) – the count is 177! Take a look – theres some more comments in the max patch, too.:

————–begin js "foldercheck.js"————–
/*

simple example of checking if a folder is empty

*/

outlets = 1;
setoutletassist(0,"info");

function path(v)
{
var f = new Folder(v);

outlet(0,"path: "+f.pathname);
outlet(0,"count: "+f.count);
f.reset();
f.close();
}

————–end js "foldercheck.js"————–

————–begin MAX patch————–

#P window setfont "Sans Serif" 9.;
#P window linecount 2;
#P comment 309 183 239 9109513 unless I press this one FIRST after I reinstantiate the js object (by retyping ".js" for example).;
#P window setfont "Sans Serif" 12.;
#P window linecount 1;
#P comment 58 271 315 9109516 Trying to find out what drives exist on a windows system!;
#P window setfont "Sans Serif" 9.;
#P comment 309 167 239 9109513 this also gives a count of 177 files -;
#P message 254 166 54 9109513 path C:/jsk;
#P window linecount 2;
#P comment 296 129 239 9109513 (use the folderiter.js example to see what the files are – they seem to be cursor resources!);
#P window linecount 1;
#P comment 297 114 239 9109513 I don’t have a D: drive , but I get a count of 177 files??;
#P window linecount 3;
#P comment 258 38 153 9109513 I started to try the same thing in js , but non-existent drives report odd results.;
#P window linecount 1;
#P comment 14 22 153 9109513 this works , but is slow;
#P newex 17 213 56 9109513 print VALID;
#P message 255 90 42 9109513 path C:/;
#P message 256 112 42 9109513 path D:/;
#P button 15 41 15 0;
#P newex 17 187 27 9109513 gate;
#P newex 14 114 63 9109513 route symbol;
#N coll ;
#T flags 1 0;
#T 0 A;
#T 1 B;
#T 2 C;
#T 3 D;
#T 4 E;
#T 5 F;
#T 6 G;
#T 7 H;
#T 8 I;
#T 9 J;
#T 10 K;
#T 11 L;
#T 12 M;
#T 13 N;
#T 14 O;
#T 15 P;
#T 16 Q;
#T 17 R;
#T 18 S;
#T 19 T;
#T 20 U;
#T 21 V;
#T 22 W;
#T 23 X;
#T 24 Y;
#T 25 Z;
#P newobj 14 90 53 9109513 coll;
#P newex 14 61 61 9109513 t dump reset;
#P newex 16 139 57 9109513 sprintf %s:/;
#P newex 17 165 32 9109513 folder;
#P newex 201 223 26 9109513 print;
#P newex 201 193 77 9109513 js foldercheck.js;
#P comment 298 92 153 9109513 this works , since I have a C: drive;
#P connect 9 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 7 0;
#P connect 7 0 4 0;
#P connect 7 1 4 0;
#P connect 4 0 3 0;
#P connect 3 1 8 0;
#P connect 8 0 12 0;
#P connect 4 0 8 1;
#P fasten 17 0 1 0 259 188 206 188;
#P fasten 10 0 1 0 261 132 206 132;
#P fasten 11 0 1 0 260 109 206 109;
#P connect 1 0 2 0;
#P window clipboard copycount 21;

————–end MAX patch————–


April 25, 2006 | 12:10 am

Hi Peter,

This is known and has been fixed for the next MaxMSP unpdate for Windows.

Here is a copy of the jsfolder object for you to test for us until the release .

http://www.cycling74.com/download/jsfolder.zip

Cheers

-Andrew


April 28, 2006 | 4:28 pm

Great! This is giving counts of 0 for non-existent drives. Thanks for
the update.

here’s a (slow) way of using js for checking for valid drives on a
windows system:

/*

simple example of checking if a folder is empty

*/

outlets = 1;
setoutletassist(0,"info");

var letters = new Array() ;
letters[0] = "A" ;
letters[1] = "B" ;
letters[2] = "C" ;
letters[3] = "D" ;
letters[4] = "E" ;
letters[5] = "F" ;
letters[6] = "G" ;
letters[7] = "H" ;
letters[8] = "I" ;
letters[9] = "J" ;
letters[10] = "K" ;
letters[11] = "L" ;
letters[12] = "M" ;
letters[13] = "N" ;
letters[14] = "O" ;
letters[15] = "P" ;
letters[16] = "Q" ;
letters[17] = "R" ;
letters[18] = "S" ;
letters[19] = "T" ;
letters[20] = "U" ;
letters[21] = "V" ;
letters[22] = "W" ;
letters[23] = "X" ;
letters[24] = "Y" ;
letters[25] = "Z" ;

function path(v) //input a path, outputs the path and the count
{
var f = new Folder(v);

outlet(0,"path: "+f.pathname);
outlet(0,"count: "+f.count);
f.reset();
f.close();
}

function drives() //just send the message "drives" and you’ll get the
drives that have something in them

{
for (var i=0;i< =25;i++) {
var check = letters[i]+":/";
var f = new Folder(check);
if (f.count > 0) {
outlet(0, f.pathname);
}
}
}


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