Joe said:
WinXP Pro lets me print the listing of files in a directory (folder). But I
am more interested in using that list electronically, such as inserting it
in a document or e-mail. Is there a way to do so?
Use the 'tree' DOS command. Open a command shell (cmd.exe) and run:
tree <parentfolder> > tree.txt
<parentfolder> is the parent folder whose subfolders you want to list. If
the path and/or folder name include spaces, you need to enclose it within
double quotes, like "c:\program files\microsoft office". You can use any
path and file name for the redirected output (treelist.txt was just an
example that would generate the file in the current folder). Any any
editor, like Notepad, to read the output file (and to print it or copy to
the clipboard).
If you don't like the appearance of upper-ASCII characters to show the
hierarchy, add the /a command-line parameter. For help, run "tree /?".
In fact, you could use one command line, like (all on one line):
tree /a <parentfolder> > _tree.txt && cmd /c notepad.exe _tree.txt && del
_tree.txt
Remember to double-quote the parentfolder if it contains spaces. You do the
'tree' command to list the subfolders. Its output gets redirected into a
file (that I preface with "_" to ensure its filename doesn't match on a
command). You load a new command shell (to pause command execution in the
current shell) and read the file using Notepad. When you exit Notepad, its
command shell unloads and the next command gets executed. The 'del' command
does cleanup so you're not left with a remnant file. Of course, you could
write a .bat or .cmd file that does the same thing, like a showtree.bat
batch file containing:
@echo off
tree /a %1 > _tree.txt
if not exist _tree.txt exit
notepad.exe _tree.txt
del _tree.txt
which you would call by entering "showtree <parentfolder>". Again, remember
to double-quote the folder name if it or the parh to it contains spaces.
If you don't want to always give the path to the showtree.bat file for
wherever you stored it (as in "c:\batch\showtree.bat <parentfolder>"), add
the folder where you stored it in the PATH environment variable (right-click
My Computer, Properties, Advanced, Environment Variables, add or update PATH
variable as a System variable so it is available to all user accounts), or
store the .bat file in a folder already searched, like c:\windows or
c:\windows\system32 although you are polluting the OS folders. I prefer to
create a C:\Batch folder where I save all my batch files and then add it to
the system PATH environment variable (at the head of that variable's value
so that folder gets searched first since I might create batch scripts that
mask internal or external commands). So my system PATH environment variable
looks like "PATH=C:\Batch;<otherfolders>". Then I can enter showtree
(although I typically include the extension, like showtree.bat, to ensure
that I mean a batch file instead of an executable, like showtree.exe) when
you want to run that batch file at a command prompt.
Normally I would add more to the above batch file for error checking and
ensuring a uniquely named output file but this one should suffice for you.