Use batch to print a directory tree of a target computer

 by theknight
cartoon-tree-thumb8412489.jpg
Ok, so in this Instructable I will be telling you how to make and use a program (using batch) that will make a text file containing a directory tree of a computer of your choice. For the program to work you have to have physical access to the target computer.

What is a directory tree? And Why is it useful?
Well, a tree is like a spider diagram of all the files and folders in a directory, giving you the information to work out the exact location and directory string of any file in the C:/ drive of a computer. The files will not be able to be opened from this program, but you will be able to see there names and types. The information can then be used for you to go away and make a 'worm' to find and retrieve the desired file.

I'll start by showing you the basics of the batch program and then continue to give options to where you can take it further. I personally have this program on a spare 52MB USB that I got free on a University open day. I use an .inf file to start the program upon recognition of the USB, then the program (which I converted to a .exe) runs as a ghost program, creating the text file, saves it on the USB directory, and then you're done! And it only takes a few seconds!

Disclaimer - I am not responsible for the use of this information, any laws or computers you break is your own doing. I am merely supplying this information for researching purposes.

Think you're ready? Then let's go -->

 
Remove these adsRemove these ads by Signing Up

Step 1: This tree is anything but leafy...

It took me a long time to work out how to do this, and as far as I know there isn't anything on the Internet that tells you how, but there was one vital thing I was missing in all my previous attempts, which I will explain later.

So, the code. If you've stumbled upon this Instructable I assume you've made batch programs before, and some of the concepts here aren't for beginners. Never the less I will explain the code as best I can. I will also assume that you know how to make and save a batch file.

The Code:

@echo off
Set USB=%CD%
CD C:\
echo tree /a /f >%USB%\echotree.cmd
%USB%\echotree.cmd >%USB%\results.txt
exit

Yes it really is that simple...

Okamiryu says: Feb 3, 2010. 2:00 PM
Pretty nifty, what would make this cooler would be if you can get it to record what hidden files were in the folders too
theknight (author) in reply to OkamiryuFeb 3, 2010. 4:30 PM
Thanks, i'm not 100% but it might do it anyway. If it doesn't, then i'm not sure there is a way, cause /a and /f are the only two options available.

Thanks for your reply though!
Prof. Pickle in reply to theknightDec 19, 2012. 7:21 PM
The FOR command could probably do the trick, if your still active that is.
vorlock in reply to theknightFeb 12, 2010. 10:26 PM
Couldn't you just put in:
 dir C:\ /s>>log.txt

the >>log.txt at the end means right to a file called log.txt if the file is not currently there it makes it
theknight (author) in reply to vorlockFeb 13, 2010. 2:42 AM
No i'm not sure that would achieve what i'm trying to acheive. But try it and let me know how it goes!
vorlock in reply to theknightFeb 15, 2010. 9:58 PM
it works and i now can have a full map (or tree) of any local or network drive just replace the C:\ with any other drive letter and get a map of that drive
eg.
dir S:\ /s
Chad Baxter says: Sep 5, 2012. 3:12 PM
Why Dont You Join Batch Homies Group And Post Your Batch Instructables There?
EpicAwesomeness says: Apr 27, 2012. 3:45 PM
Oh, I forgot, same for:
echo tree /a /f >%USB%\echotree.cmd
echo is just there so the batch file knows that "tree" isn't the command xD
It will take the tree text, code it as ANCII, as a file, on the
%USB%\ drive, as echotree.cmd. Then that gives access for the code above to work.
Again, I hope I helped!
EpicAwesomeness says: Apr 27, 2012. 3:41 PM
For:
%USB%\echotree.cmd >%USB%\results.txt
I'm pretty sure it means that it will take the "echotree.cmd" from the %USB% drive, and > means that it will make it into a file. So, It will take that file, and save it in %USB%\ as results.txt

I hope I was of help! :)
kidmosey says: Feb 6, 2010. 12:40 AM
Maybe I'm missing something.  why can't you just say:

@tree /a /f c:\ > results.txt

in the original batch file?

theknight (author) in reply to kidmoseyFeb 10, 2010. 12:21 AM
Ahh, this makes alot more sense now.

This is true you can infact do it this way. I think all the times I tried it in this syntax I was missing the '@', which would explain the problems I had. Thanks for the comment, and insight into my errors!
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!