We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,220 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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.

6
Contributors
5
Replies
2 Years
Discussion Span
1 Year Ago
Last Updated
9
Views
Question
Answered
waaliban
Newbie Poster
3 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Shanti C
Posting Virtuoso
1,654 posts since Jul 2008
Reputation Points: 137
Solved Threads: 163
Skill Endorsements: 3

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

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

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

Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 375
Skill Endorsements: 17

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
Skill Endorsements: 0
Question Answered as of 1 Year Ago by Shanti C, essential, Taywin and 2 others

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0713 seconds using 2.7MB