Click here to Skip to main content
Click here to Skip to main content

VBScript directory crawler

By , 16 May 2000
 
  • Download source files - 1 Kb

    Sample Image - walker.jpg

    This VBScript can be used in a number of ways. At its heart, it's a simple directory tree walker. I wrote it originally as a DevStudio macro to clear out all the big leftover files in the debug and release folders. I added a bit of code to it on a whim to make it to indent the subfolders and add the various lines so that in the end it looks similar to the left hand frame of explorer. This can then be piped to a file and printed (have you ever wanted to print out a directory tree? I know I have.)

    I have commented where you could put code to do things like clear out temp files, whatever.

    Enjoy :)

  • License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Ron Olson
    Web Developer
    United States United States
    Member
    No Biography provided

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    GeneralDocument Properties helpsussLen Inkster26 Jul '05 - 8:40 
    Is there a way I can examine office document properties (The internal ones such as Author, Comments etc) using a vbscript?
     
    I can't find any reference on the MS VBScript site for any FSO Object that might help
     

    GeneralRe: Document Properties helpsussMathew Gorge27 Jul '05 - 21:28 
    'VBScript file to get the author and comments
    'Tested with Word 2000
     
    Dim strAuthor, strComments
     
    Set objWord = CreateObject("Word.Application") 'Open an instance of Word
     
    'Open an word document and return the "Documents" object
    Set objDoc = objWord.Documents.Open("D:\Debug\Test1.doc")
     
    strAuthor = objWord.ActiveDocument.BuiltInDocumentProperties(3) 'wdPropertyAuthor
    strComments = objWord.ActiveDocument.BuiltInDocumentProperties(5) 'wdPropertyComments
     
    MsgBox "This document's author is " & strAuthor & vbCrLf &" Comments: " & strComments
     
    'msgbox objWord.Version
     
    'To avoid the "Do you want to save your changes?" dialog box, the script
    'sets the Saved property to TRUE before terminating Word.
    objDoc.Saved = TRUE
    objWord.Quit
     

    =========================
    Do not look into FSO because they can only read the binary format of word.
    Use COM to access method of word
     
    Refer MSDN for reference
    QuestionWhy it Fails?memberdougcranston27 Feb '03 - 4:50 
    Very intrigued with the code, however, when running it on a Win2000 system, (logged on user has Admin permissions), the program runs but dies apparently when it hits a "system directory" Error message is:
     
    d:\_script\bertha_index.vbs(58,2) Microsoft VBScript runtime error: Permission denied
     
    The last directory displayed was "System Volume Information" which is a "system directory".
     
    Any suggestions on how to bypass system or hidden directories to preclude this error?
     
    Again, enjoyed the scripts concept, and hope to hear from you in the near future.
     
    Thanks for your time and efforts.
     
    Doug CranstonConfused | :confused:
    AnswerRe: Why it Fails?memberJim Smith15 Oct '04 - 8:09 
    To bypass, you can use the attributes property on the folder object to see if it a system folder or not, and skip as needed.
     
    js
    GeneralRe: Why it Fails?memberdougcranston15 Oct '04 - 8:18 
    Thanks for your response...Been a long time.. Will try out your concept, maybe this weekend, if my to do list from my better half lets me.
     
    Have a great day.
    Dougc
    GeneralRe: Why it Fails?sussAnonymous14 Sep '05 - 14:32 
    It's failing because that folder is only accessible to the SYSTEM user by default. Modify the security settings so that the Administrator has full access rights to the folder, and after applying them, you'll be able to go into that directory as well. This particular issue has caused me a few headaches.
    GeneralShow pictures from a dir on a html-pagememberPBA20 Feb '02 - 0:43 
    I have a html-page where i want to display dynamicly all pictures
    from a certain directory.
     
    Someone any idea's howto do this
     
    Roll eyes | :rolleyes:
     
    PBA
    GeneralSearchinf for a particular extension using VBscriptsussGnanavel9 Oct '00 - 20:42 
    Hi
    I have a question
    How can I do a filesearch using VBScript
    say for example if I give c:\test\*.txt
    as input it should list all the .txt file
    under test directory.
    Can anyone help me?
    Regards
    Gnanave
    GeneralRe: Searchinf for a particular extension using VBscriptmemberdzb00724 Nov '00 - 8:21 
    Not sure if this might be a supplement to help you, worth a shot. Check out MS (HOWTO: Search Directories to Find or List Files)
    I used some of the sample code from this page and tweaked it to build a tool to retrieve all files within a directory (& subs) into an Access database... it was VERY helpful. As it searches (and stores if you like) the files, you can split the extension to retieve only those files. You can also use this to exclude file-types within your search. The code is VB, but i used in Access just to make my life easier to store into a Database. Email me & i'll send you the tool, if you like (Access 97). Good luck.
     
    http://support.microsoft.com/support/kb/articles/Q185/4/76.ASP
     

    GeneralNice! + More on scriptssussPhilippe Lhoste23 May '00 - 22:59 
    I like it, it is a nice introduction to the use of FileSystemObject with VBScript.
     
    I started playing with the code, here is a small patch:
     
    dim sf, fileColl, line
    for each sf in foldcol
    spacer = spacer + space(3) + "|"
     
    'wscript.echo spacer + "-- " + sf.name
     
    ' If you wanted to show the number of bytes, use these lines instead of above
    set fileColl = sf.Files
    line = spacer + "-- " + sf.name
    if fileColl.Count = 0 then
    wscript.echo line + " (empty)"
    else
    wscript.echo line + _
    " (uses " + cstr(FormatNumber(sf.Size, 0)) + " bytes with " + _
    cstr(FormatNumber(fileColl.Count, 0)) + " files)"
    end if
     
    I believe you should have no problem locating my patch in the source...
    Notice the use of '_' to continue a line (I don't know if it well documented), and the use of the Count property to have the number of elements in a collection (I couldn't locate this property in the MSDN doc!).
     
    Of course, you can use the fileColl to list the files or do something on them.
     
    Another trick for newbies like me:
    you can run the script by double-clicking on it, of course, but if you want to run it from a command line, you can either type:
    start vbscript_prog.vbs (with same result as double-clicking, ie. having each echo in a message box)
    wscript vbscript_prog.vbs (idem)
    or
    cscript /nologo vbscript_prog.vbs (with output on the standard output, so can be redirected to a file)
     
    Try cscript /? for more options.

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Permalink | Advertise | Privacy | Mobile
    Web02 | 2.6.130516.1 | Last Updated 17 May 2000
    Article Copyright 2000 by Ron Olson
    Everything else Copyright © CodeProject, 1999-2013
    Terms of Use
    Layout: fixed | fluid