Link to home
Start Free TrialLog in
Avatar of JjcampNR
JjcampNRFlag for United States of America

asked on

Export Directory Structue To File

I'm looking to get a script or find an application (free) that can successfully export a large directory structure to a file (any format - text, image, HTML, whatever) in a readable form.  I've used the Windows "tree" command however from what I've been able to figure out this only works well if the entire directory structure can be captured in the command console buffer (most of the ones I'm dealing with can't).

I know that you can do a "tree /a > file.txt" however the ASCII output gets extremely hard to read when it spans numerous pages.  The unicode output of the standard "tree" command looks fine for what I need however it looks like it's not possible to redirect the output, in unicode, to a text file even if you create the file first and save it as unicode.

If someone could get me a script, find a free (or cheap) application, or has any other way to do this it would be a huge help.

The optimal solution would be an application or script that exports the directory structure to an HTML (or other portable format) file where the folders can be expanded and collapsed like in Windows explorer.  
Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America image

see if some of this apps. helps you...
http://www.sharewareconnection.com/dirprinter.htm
http://www.programurl.com/software-dirprinter-downloadnow.html

FerG
Saludos
--
Ing. Fernando D. Giletta
MP: 4035 CIEC
San Fco. Cba. Arg.
Avatar of JjcampNR

ASKER

This looks pretty good, however it's a bit more complicated to get configured than I was looking for and it doesn't look like you can easily save the tree to send elsewhere (I may be wrong).  Can you provide any assistance with where to start looking at configuring the application to read from a specific directory on a server, produce the tree of all folders in that directory (I'm not concerned with files), and then how to save it so I can send the file to users without them having to re-run the scripts?

Dirprint installed and on the first run told me my evaluation period had ended.  I was unable to change anything but tried to view the directory structure of C:\ at which point it completely locked up.  I'll download again and see if I can get it to work, but so far not so much luck.
I'm also not seeing an easy way for Treeview to produce the trees.  From what it looks like I'd need to build the trees manually - is there a way to point it at a directory and have it construct the tree?
This exports a directory structure to an XML file, which can be displayed in a browser.  Requires a reference to Microsoft XML 2.6 or better and Microsoft Scripting Runtime.  
Option Explicit
 
Private Sub Command1_Click()
    GetFoldersRecurse "C:\temp\", "C:\temp\test.xml"
End Sub
 
Public Function GetFoldersRecurse(strPath As String, strFilename As String)
    
    Dim oFSO As FileSystemObject
    Dim xmlDoc As DOMDocument
    Dim node As IXMLDOMNode
    
    Set xmlDoc = New DOMDocument
    Set node = xmlDoc.createElement("folder")
    node.Text = GetFolderName(strPath)
    xmlDoc.appendChild node
    
    Set oFSO = New FileSystemObject
    
    Call sGetFolders(strPath, xmlDoc.documentElement, xmlDoc, oFSO)
 
    xmlDoc.save strFilename
End Function
 
Private Sub sGetFolders(ByVal strPath As String, ByRef node As IXMLDOMNode, xmlDoc As DOMDocument, ByRef oFSO As FileSystemObject)
    Dim oFolder As Folder
    
    For Each oFolder In oFSO.GetFolder(strPath).SubFolders
        Dim child As IXMLDOMNode
        Set child = xmlDoc.createElement("folder")
        child.Text = GetFolderName(oFolder.Path)
        node.appendChild child
        Call sGetFolders(oFolder.Path, child, xmlDoc, oFSO)
    Next
End Sub
 
Private Function GetFolderName(strPath As String) As String
    If Right$(strPath, 1) = "\" Then strPath = Left$(strPath, Len(strPath) - 1)
    GetFolderName = Mid$(strPath, InStrRev(strPath, "\") + 1)
End Function

Open in new window

Sorry, VB really isn't my thing....I'm getting a syntax error on line 7 character 43 (says expected ')') and I'm not seeing where the problem is.  I do have MSXML installed as well as wscript/cscript support.  Not sure if I'd need a specific Windows Scripting Runtime package or not.  Any help is greatly appreciated!
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is SO close to what I need.  Is there any way to hide the <folder></folder> tags and just put the + or - signs next to the name of the folder?  I know if I send the XML off to a user they'll be overly confused about the tags, but this is doing exactly what I need.
>next to the name of the folder?

XML tags cannot have spaces in the tagname, so we'd have to replace them with underscore, which could be problematic if there is a folder with the same name except for the underscore.... You could replace the space with * or other character that is not allowable in folder or filename....
Hum, OK.  I think this will give me what I need and I'll play around with the script a bit.  Thanks so much for the quick responses, this will save me a lot of tedious work in the next few weeks!
Thanks for the help, it's greaty appreciated!
Okay, you're welcome.  Good luck with it.