954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to list all files in a folder including subfolder files

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.

waaliban
Newbie Poster
3 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
 
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

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 + '';
e.moveNext();
} 
while ( !e.atEnd() );
return( s );
} 
</script>
</head>
<body>

<p>

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

</p>

</body>

</html>
essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 
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

svaughn8891
Newbie Poster
1 post since Oct 2010
Reputation Points: 10
Solved Threads: 1
 

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

Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
 
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.

nudelsalat
Newbie Poster
2 posts since Aug 2011
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You