Consulting

Results 1 to 2 of 2

Thread: VB Code to map directories?

  1. #1

    VB Code to map directories?

    Hi, im hoping someone can assist with this (not sure if right forum section).

    Im wanting some VB code that will work through a given direcoty (e.g C:\Windows) and make a note of each file/folder found in that directory and print it into a txt document.

    All help greatly appreciated

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Well you can have vb code to do that if you really want, but you can do that natively. In windows operating system you can use the ">" to write/overwrite a file and ">>" to append to a file. So from the command prompt
    Echo I am a test > Test.txt
    would create (or overwrite) the test.txt file and write "I am a test" to the file. But you can redirect any output that would have gone to the console window to a text file. For instance "Dir" So Dir > Text.txt would send the output to test.txt. That pretty much rules right?

    So now let's talk about the DIR command. DIR get a bad rep for being slow, but it's not slow, it's just accessing a lot of info. When you do a normal DIR it's pulling creation dates, modifiation dates, in some cases owner, etc etc. However if you just want a list of files use the "/B" switch (bare) to dump only file names, if you use "/S" (do subdirectories) it will also list the folder path. Which is of course "made of awsumm"

    Ok last but not least, include hidden/system files and exclude directories with "/A : D" (no spaces) and redirect to the file of your choice and you have something that looks like this:
    Dir /A-D /B /S > C:\DirDump.txt
    Did I mention it should run instantly(ish)? Did I also mention you can just do it from the run box? Like this:
    cmd /c "Dir /A-D /B /S > C:\DirDump.txt" && Start notepad.exe C:\DirDump.txt
    Did I mention that if you just have to do it from VBA you can just:
    [vba]Shell "Dir /A-D /B /S > C:\DirDump.txt"[/vba] OK I'm done now
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •