simple way of getting a text file of a folder's contents (PC)

I have lots of folders with hundreds of files in them. I would like to get text files of all the names of the files in each folder in order, and maybe attributes (date size). Is there a simple program or command that would allow me to do it (using XP)?

Try “dir” from the command-line.

I’ve worked out a nifty little windows utility for this, and maybe I’ll actually figure out some way to distribute it as freeware.

Basically, the way I’ve got it set up, (which does require a bit of registry tweaking,) I can just right click on a folder in ‘my computer’ or ‘windows explorer’, pick ‘listfiles’ as one of the context-menu option, and after a little thought, a new window appears, containing a huge textbox, listing all of the filenames. You can then copy-paste out of there to wherever else you want the text.

When you have to do it often, it’s much handier than dir redirection, I find.

dir . | text.txt

In a DOS prompt I think you mean dir . > text.txt

The " | " is for paging the output.

If you just want the names of the files use “dir /b . > text.exe”

If you want a file with the contents of the subdirectories too it’s “dir /s . > text.exe”

Close but no cigar.

“|” is for piping, not paging. It sends the result of the first command to the second. If the second command is the “more” command (which does paging) then you get paged output. If it’s something else, you get whatever that command does.

You’re still correct that “dir . | test.txt” is wrong, since test.txt is not a valid command.

In your latter two examples you redirected to test.EXE. That should have been test.TXT. Probably just a typo, but a critical one.
chrisk: You can combine your shell context registry entry technique with the dir > txtfile concept & end up with a right click menu option that opens Notepad with a folder listing. That eliminates the requirement to deploy any code anywhere. Your “shareware” becomes a simple .reg file that adds 1 entry to the registry.

Something I find very handy to have done:

How to add the Print Directory feature for folders in Windows XP (a Microsoft KB article).

I know it doesn’t limit itself to text files, but I’m assuming that lots of people interested in this thread will have use for it.


Give LS - File List Generator a go. There’s ways to do it through MS-DOS, but I’m not sure about your familiarity with DOS commands.

Well absolutely great :frowning: I followed the instructions and yes it did change my default of a double click on a folder to start search rather than open the folder.

So I went to the last part with the registry editor and tried to do the change it suggested. In step 3 I have no “modify” under my edit menu – so now what?

I’m running Windows XP Version 5.1.

Is there a different way to run registry editor other than typing regedit in the start\run box?
Never mind I see you have to highlight “default” first – then you get a modify choice.

This actually prints the directory listing to the printer. The key is the batch file below:

@echo off
dir %1 /-p /o:gn > “%temp%\Listing”
start /w notepad /p “%temp%\Listing”
del “%temp%\Listing”
But what I’d really like is for notepad to stay open with the directory listing in it, so it could be cut and pasted someplace else. I’m guessing what I want is to
remove the /p switch to make it not print
remove the exit command so notepad stays open

Is that correct?

Heh. I was showing the interns only a couple of weeks ago how to get a listing of the programs they needed to work on with dir *.fmb > fsource. txt.

“Now you can put DOS on your resume!” I exclaimed. They just looked at me.

I’ve been using Karen’s Directory Printer for several years. It’s handy, and it’ll make a text file of whatever attributes you select. And it’s free.

I think so… and adding *.txt after the dir %1 should bring up only .txt files (or whatever else you want to limit it to) if you have the reason.
The Karen’s Directory Printer looks great!

So instead of a pipe, you should use an elbow…

just what I was looking for - thanks

didnt really want to mess around with DOS or shell commands

What does the %1 do? And what do the switches /-p, /w, and /p mean?

My annotations:
@echo off
turn off output to the shell

dir %1 /-p /o:gn > "%temp%\Listing"
Do the dir command against the first parameter (%1) to the batch file printdir.bat. %1 is the first parameter, %2 the second, etc. If you do “printdir c: est.txt” then %1 contains “c: est.txt”. “/-p” means “don’t pause between screens.” “/o:gn” means “list directories first, followed by file names in alphabetical order”.

start /w notepad /p "%temp%\Listing"
start the Windows program “notepad” and then wait for it to end before going on to the next command (/w for /wait). I am not certain, but my guess is that “/p” stands for /print, which makes notepad print the temp file as soon as it (notepad) opens.

I think that LS is better than Karen’s in that you don’t need the extra Visual Basic cruft. Both should work, though.

I have been using “dir” for untold number of years to hack files. I do a dir listing to a text file, then use Vi or sed or grep or whatever to turn the text file into a batch job that executes a command against each file. Yeah, you can use un*x “find” to do this too, but the find syntax is often so gnarly that a shell/batch command is easier to get going.