From fbc81cccf59a110f0a0380e941da2fae7fa80ea3 Mon Sep 17 00:00:00 2001 From: "pete%alphanumerica.com" Date: Tue, 15 Aug 2000 12:37:40 +0000 Subject: [PATCH] added readDir(dirPath) member function. Also fixed a small bug in copy to return if the source file is a dir. r=dougt --pete git-svn-id: svn://10.0.0.236/trunk@76328 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpcom/tests/utils/io.js | 49 ++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/mozilla/xpcom/tests/utils/io.js b/mozilla/xpcom/tests/utils/io.js index 2669290d182..2bfc05be342 100644 --- a/mozilla/xpcom/tests/utils/io.js +++ b/mozilla/xpcom/tests/utils/io.js @@ -38,6 +38,7 @@ Contributor(s): Pete Collins, Doug Turner, Brendan Eich, Warren Harris * 8. rm(path); * 9. copy(source, dest); * 10.leaf(path); +* 11.readDir(dirPath); * * Instructions: * @@ -114,7 +115,7 @@ exists : function (path) { try{ - var file = new FilePath(path); + var file = new FilePath(path); var fileExists = file.exists(); } @@ -265,7 +266,7 @@ write : function(buffer, perms){ try{ if(!this.fileChannel) - this.fileChannel = new FileChannel(); + this.fileChannel = new FileChannel(); if(perms){ @@ -390,7 +391,7 @@ mkdir : function(path, permissions){ try{ - this.fileInst = new FilePath(path); + this.fileInst = new FilePath(path); if (!fileExists){ @@ -490,6 +491,11 @@ copy : function (source, dest) { var copyName = fileInst.leafName; + if(fileInst.isDirectory()){ + dump("Sorry, you can't copy a directory yet\n\n"); + return + } + if(!this.exists(dest) || !dir.isDirectory()){ copyName = dir.leafName; dump(dir.path.replace(copyName,'')+'\n\n'); @@ -520,7 +526,6 @@ copy : function (source, dest) { catch (error){ dump("**** ERROR:"+error+"\n\n"); } this.close(); - }, /********************* COPY *****************************/ @@ -544,6 +549,42 @@ leaf : function (path) { /********************* APPEND ***************************/ +/********************* READDIR **************************/ + +readDir : function (dirPath) { + + if(!dirPath){ + dump('Please enter a dir path as arg\n'); + return null; + } + + if(!this.exists(dirPath)){ + dump("Sorry, directory "+dirPath+" doesn't exist\n\n"); + return; + } + + var file = new FilePath(dirPath); + + if(!file.isDirectory()){ + dump("Sorry, "+dirPath+" is not a directory\n\n"); + return; + } + + var files = file.directoryEntries; + var listings = new Array(); + + i=0; + while(files.hasMoreElements()){ + listings[i] = files.getNext().QueryInterface(Components.interfaces.nsILocalFile).path; + i++; + } + + return eval(listings.toSource()); + +}, + +/********************* READDIR **************************/ + append : function (dirPath, fileName) { if(!dirPath || !fileName){