[Jslib] Re: File IO

Pete Collins pete at mozdev.org
Sat Jul 26 13:53:43 EDT 2003

Here's what i came up w/.

I'm sure you can trim this code down and make it less verbose.

function test () {
   var d = new Dir('/tmp');
   var dirList = d.readDir();

   var dirs = new Array();
   var files = new Array();

   for (var i=0;i<dirList.length;i++)
     dirList[i].isDir() ?  dirs.push(dirList[i]) : files.push(dirList[i]);


   dirList = new Array();
   dirList.push((new Dir(".")));
   dirList.push((new Dir("..")));

   for (i=0;i<dirs.length;i++)

   for (i=0;i<files.length;i++)

   for (i=0;i<dirList.length;i++)



Is this the end result you want to achieve?


Jacob Emcken wrote:
> Hi
> I use the the readDir() to generate an array with all the files and dirs
> in the current path.
> Now I want to append a Dir object in the beginning og the array with the
> parent directory i.e.
> var dir = new Dir(path);
> var dirList = dir.readDir();
> var parentDir = dir.parent;
> parentDir.leaf = "..";
> dirList.unshift(parentDir);
> But if I alter the leaf the path gets all fucked up :(
> I'm probaly doing this the wrong way but I want to make a loop that list 
> the files and dirs in a list with the parent dir first like this.
> ..
> Documents
> .mozilla
> .gaim
> example.txt
> test.swx
> etc.
> The resaon why I want just to alter the leaf is to avoid having if-else 
> in my loop.
> Thanks
> -- Jacob

More information about the Jslib mailing list