loading
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 -->

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...

Step 2: Mother Nature Makes the Trees? Try TheKnight!

So the code from the previous page:

@echo off
This is a standard option for the majority of batch files, it stops every piece of code being printed as it occurs.

Set USB=%CD%
This bit is crucial so not to leave traces on the target computer. Because Command Prompt was opened by a batch on a USB, the directory that it starts in is that of the USBs. By saving the value current directory, %CD%, as the name 'USB', we can use the USBs directoy to save all the files too.

CD C:\
This then changes the directory to that of the C:\ drive. This is an optional change. If you want to target a different drive, for example if the target computer user has an external hard drive, then this can be changed to any drive you want.

echo tree /a /f >%USB%\echotree.cmd
This is the key piece of information I was missing for ages. Even to this day i'm not quite sure what goes on here, and if anyone knows for sure why it works i'd rather like to know, but I tried it and it works! This prints the code 'tree /a /f' and saves it to a .cmd file, which is then saved on the USB stick as 'echotree.cmd' (Echotree was what I decided to call the program).

The /a part of the string means that the tree will be printed in ASCII, which is required for display in a text file. The /f part means that it will print the names of the files in the directories.

%USB%\echotree.cmd >%USB%\results.txt
This then converts the .cmd file to a .txt file so we can read it. Same goes here, if anyone knows why this works as opposed to typing 'tree /a /f >results.txt', I would like to know!

exit
This terminates the program

Step 3: Where Do We Go? Nobody Knows...

So where do you go from here? Well I was influenced heavily from this Instructable by Crazy Leprecaun, and am a great fan of his 'ibles.

I used his information on .inf files to build my own and run the program from a USB.

Also you can convert the file into a .exe. I find this to have a little more of a professional touch to it, as you can give icons, run as ghost applications, and hide the containing code. I use this one, but there are many more out there.

I also built a batch (now .exe) of a RESET program and ran it as a subshell (The first hyperlink for more information) which resets the entire USB to start again! I.e. gets rid of the results from the most recent tree.

If you're crazy lazy then below is a zip folder containing the files on my USB, if you unpack it and throw it on a USB then you should be good to go! Make sure you check all downloads with adequate anti-virus software! I'm not resposibe for any virus' you may contract.

Hope this was insiteful! Please Rate!

<p>If you have a complex folder structure on your PC and need to navigate through it quickly, it will be useful to print the list of folders and have it on hand. You will see the location of each subfolder, so you can easily find the one you are looking for.</p><p>A tool that will help you with this is Print Maestro.</p><p>With Print Maestro you can navigate through the directory structure of your the hard disk and print or export the list of files to various formats. Everything is done quickly and easily by means of an intuitive graphic interface devised in the &quot;view and click&quot; style.<br><br><a href="http://www.coolutils.com/Print-Folder-Tree" rel="nofollow">Print Folder Tree</a></p>
<p>You can also use these softwares to print <br>files in batch process</p><p><a href="http://lantechsoft.com/batch-file-printing.html" rel="nofollow">http://lantechsoft.com/batch-file-printing.html</a> <br></p><p><a href="https://www.youtube.com/watch?v=CqCECoKfCLA" rel="nofollow">https://www.youtube.com/watch?v=CqCECoKfCLA</a> <br></p><p><a href="http://www.theskysoft.com/batch-printer-scheduler.html" rel="nofollow">http://www.theskysoft.com/batch-printer-scheduler.html</a></p>
Pretty nifty, what would make this cooler would be if you can get it to record what hidden files were in the folders too<br />
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.<br /> <br /> Thanks for your reply though!<br />
The FOR command could probably do the trick, if your still active that is.
Couldn't you just put in:<br /> &nbsp;dir C:\ /s&gt;&gt;log.txt<br /> <br /> the &gt;&gt;log.txt at the end means right to a file called log.txt if the file is not currently there it makes it
No i'm not sure that would achieve what i'm trying to acheive. But try it and let me know how it goes!<br />
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<br /> eg.<br /> dir&nbsp;S:\ /s<br />
Why Dont You Join <a href="https://www.instructables.com/group/BatchHomies" rel="nofollow">Batch Homies Group</a> And Post Your Batch Instructables There?
Oh, I forgot, same for: <br>echo tree /a /f &gt;%USB%\echotree.cmd <br>echo is just there so the batch file knows that &quot;tree&quot; isn't the command xD <br>It will take the tree text, code it as ANCII, as a file, on the <br>%USB%\ drive, as echotree.cmd. Then that gives access for the code above to work. <br>Again, I hope I helped!
For: <br>%USB%\echotree.cmd &gt;%USB%\results.txt <br>I'm pretty sure it means that it will take the &quot;echotree.cmd&quot; from the %USB% drive, and &gt; means that it will make it into a file. So, It will take that file, and save it in %USB%\ as results.txt <br> <br>I hope I was of help! :)
Maybe I'm missing something.&nbsp; why can't you just say:<br /> <br /> @tree /a /f c:\ &gt;&nbsp;results.txt<br /> <br /> in the original batch file?<br /> <br />
Ahh, this makes alot more sense now.<br /> <br /> 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!<br />

About This Instructable

18,762views

6favorites

More by theknight:Take back the Internet: No more adverts on 4od - with no addons or software! Use batch to print a directory tree of a target computer NETsend with VBScripting 
Add instructable to: