1,105,585 Community Members

How to list all files in a folder including subfolder files

Member Avatar
waaliban
Newbie Poster
3 posts since Aug 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-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.

Member Avatar
Shanti C
Posting Virtuoso
1,675 posts since Jul 2008
Reputation Points: 106 [?]
Q&As Helped to Solve: 165 [?]
Skill Endorsements: 4 [?]
 
0
 
Member Avatar
essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 84 [?]
Q&As Helped to Solve: 138 [?]
Skill Endorsements: 0 [?]
Featured
 
-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>
Member Avatar
svaughn8891
Newbie Poster
1 post since Oct 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
Taywin
Posting Maven
2,632 posts since Apr 2010
Reputation Points: 134 [?]
Q&As Helped to Solve: 378 [?]
Skill Endorsements: 17 [?]
 
-1
 

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

Member Avatar
nudelsalat
Newbie Poster
1 post since Aug 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
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 svaughn8891, nudelsalat, Shanti C and 2 others
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article