View Full Version : VB Code to map directories?
chris_uk_lad
06-25-2008, 09:59 AM
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 :)
Oorang
06-25-2008, 06:43 PM
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:
Shell "Dir /A-D /B /S > C:\DirDump.txt" OK I'm done now;)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.