1.11M Members

How to list all files in a folder including subfolder files

 
-1
 

Hello friends,
I want to write a javascript to list of all files in a folder including files in the subfolders. This is for the scorm purpose to list all the files. some examples are listing files but not listing the files inside the subdirectories. I want the file's full path like C:\Documents\javascript\wilson.js like this.

 
0
 
 
-1
 

Please feel free to modify this code to match your needs. If you have any question regarding this code you can document.write('Me on my inbox'). lol! Have a good day...

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Some Title</title>
<script type="text/javascript">
function showAvailableDrives()
{
document.write( getDriveList() );
} 

function getDriveList()
{ 
var fso, s, n, e, x;
fso = new ActiveXObject('Scripting.FileSystemObject');
e = new Enumerator( fso.Drives );
s = '';
do
{ x = e.item();
s = s + x.DriveLetter;
s += ':- ';
if ( x.DriveType == 3 ) n = x.ShareName;
else if ( x.IsReady ) 
n = x.VolumeName;
else n = '[Drive not ready]';

s += n + '<br>';
e.moveNext();
} 
while ( !e.atEnd() );
return( s );
} 
</script>
</head>
<body>

<p>

<script type="text/javascript"> 
showAvailableDrives(); 
</script>

</p>

</body>

</html>
 
0
 

Hello friends,
I want to write a javascript to list of all files in a folder including files in the subfolders. This is for the scorm purpose to list all the files. some examples are listing files but not listing the files inside the subdirectories. I want the file's full path like C:\Documents\javascript\wilson.js like this.

A more web approach to this would be to use the XMLHTTPRequest object to fetch a directory (instead of a file) from a web server. This will bring back an HTML page which list the files in the directory. You can then parse through the html and find the directories. With apache you can recongnize a directory because there will be a link with the href value equal to the text node in the link.

Obviously if the http server doesn't allow listing a directory, this won't work.

Here is some code that I use. The XML.getFile function below just wraps and XMLHTTPRequest.

var operationsHTML = XML.getFile(env + '/operations/').responseText;
   var linkStart = 0
   var linkEnd = 0
   while (linkStart <= linkEnd) {

      linkStart = operationsHTML.indexOf('<a', linkEnd);
      if (linkStart > -1) {

         linkEnd = operationsHTML.indexOf('</a>', linkStart) + 4;
      
         if (linkEnd > -1) {

            var hvs = operationsHTML.indexOf('href="', linkStart) + 6;
            var hve = operationsHTML.indexOf('"', hvs) - 1;

            var tnvs = operationsHTML.indexOf('>', linkStart) + 1;
            var tnve = operationsHTML.indexOf('<', tnvs) - 1;

            if (operationsHTML.substring(hvs, hve) == operationsHTML.substring(tnvs, tnve)) {

               alert(operationsHTML.substring(tnvs, tnve))
               operations[operationsHTML.substring(tnvs, tnve)] = null;
            }
         }
      }
   }

Steve

 
-1
 

Old old thread... 2 years old!!!

 
0
 

Old old thread... 2 years old!!!

But unlike your post, svaughn8891s post was helpful for me. Stumbled over it after searching for a solution with google and I'm glad he did answer after 2 years.

Question Answered as of 2 Years Ago by Taywin, svaughn8891, nudelsalat and 2 others
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article