How to create a Text file from a directory/folder
of files
The other day I was backing up some data on my hard
drive using a program called Sonic something. But I got the message
"Name too long (106 characters Maximum)". I had to rename a few dozen
html files and the directories that they pointed to. There were hundreds
of files and folders in the list and I did not want to loose these very
discriptive file names, but I could not back them up unless I made the
changes. I thought that if I had a text file listing all of the file
names, then I would not loose the information. Now the question was
"What's the best way to get hundreds of file names into a text file?".
I used to be pretty good at MS DOS (when DOS was all
there was) so I tried the commands that I could still remember. I knew
that if I used a "dir" command I could get a complete listing of all
of the files in a given directory. So I went to DOS by clicking the
Start button and clicking Run. Then I typed "cmd" (if I was using Windows
95 or 98 I would have typed "command") and hit enter. By the way I did
not type any quotation marks when I was typing that is just to make
what I typed stand out in this text. This brought up a DOS window. I
typed "dir" and hit Enter (the enter key on the keyboard) and sure enough
it listed all of the hundreds of file names.
So, I thought to myself, all I need to do now is copy
the text and paste it into an empty document file. Again this is DOS
so things are a little than Windows. In Windows XP to highlight the
text you have to Right Click and choose "Select All" from the menu and
then hit Enter to copy. (In all versions of MS Windows the right mouse
button brings up different menu options depending where you click. It
will give you one menu if you right click a blank spot on the desk top,
a different menu if you right click an , and still different menus in
most of your programs. If you have not tried it before, you should really
give it a try.) Then paste as usual in Notepad. But when I looked at
the list most of it was missing. The list was larger than the memory
buffer in the DOS window.
So I dug around in my memory for more for some of the
options that went with the dir command, and I remembered "/p" this would
let me page through the list one screen at a time. So I went back to
the DOS window and typed "dir /p" (remember, if you are doing this too,
don't use the " marks) and hit Enter. It listed the first 19 files,
so I copyed and pasted them, then I hit Enter to see the next page and
repeated the process a dozen times before I hit "Control C" ("Control
C" is used in most text editing programs to Copy text.) by mistake.
When you hit "Control C" in DOS it means "Quit what you are doing!"
which was of course not what I wanted to do. I had to start over, find
the place I left off and pick up from there. After doing that a few
times I decided that there must be a better way.
I went to the page MSDOS
Help and found DOS
Command Index but they did not have what I wanted, I finally found
what I wanted on the MS website: Using
command redirection operators
My goal was a text file. What I needed was a command
to copy the directory listing directly to a file with no steps in between.
And that is what I found. "dir>filename.txt" where filename stands
for the name I wanted the file to be. I actually used the file name
dirfile.txt because I thought that it described the file fairly well.
If I had wanted a listing of all the files, directories and their subdirectories
I would have used the command "dir/s>filename.txt".
After that I just renamed the files and burned them
to DVD. I also put a copy of the file on the CD for reference.
Synopsis:
How to turn a directory listing into a text file.
Click the Start button in the lower left hand corner
of the desk top.
Click Run and then type "cmd" (do not type the
quotes) and then hit enter.
Change directories as needed.
Type "dir>filename.txt" (again do not type the
quotes) and remember that filename.txt stands for the name of the file
you want to create with the directory listing.
PC Help