XML/XSL Portal

Multiple Stylesheet Aware
HideXML TutorialHide
     
  
 
 

dirTOxml

A few people have asked how to get a directory listing as xml. I wrote this little command line JavaScript utility for this purpose.

Depending on how you have scripting set up one of the following 3 methods will produce an xml file containing a directory listing.

cscript dirTOxml.js folder xmlfile

wscript dirTOxml.js folder xmlfile

dirTOxml.js folder xmlfile

Example

dirTOxml.js "c:\temp" "xmlfile.xml"

The quotes are only needed if there are spaces in the folder or file spec.

It increments a file count attribute each time it outputs a <file> tag but this can easily be modified to output file attributes by changing the following line.

outFile.WriteLine(pad(d) + "<file name=\"" + enumerator.item().name + "\" number=\"" + number + "\" />");

i.e. If you want the create date.

outFile.WriteLine(pad(d) + "<file name=\"" + enumerator.item().name + "\" DateCreated=\"" + enumerator.item().DateCreated + "\" />");

Download

Or try version 2 included in the zip that does all of the above. Just make sure you have enough disk space for the output.

One possible stylesheet to display the output is included.

Petr Cimprich has written a perl version which works slightly differently but you should be able to use the stylesheets with a little modification.

As this is a common FAQ I decided to create a more complex version of the stylesheet (dirtoxmlimg.xslt) with images. To view it correctly put the images in the same folder as the resulting HTML. Just right-click and Save Picture As

For the treeview

           

For files

                             

 
 
  
     
Open

Delete

View XML
View XSL