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

**URL:** <https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793>\
**Category:** Factual Questions\
**Created:** [July 31, 2007, 8:15am UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793 "2007-07-31T08:15:21Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![scm1001](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@scm1001](https://boards.straightdope.com/u/scm1001)\
**Post date:** [July 31, 2007, 8:15am UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/1 "2007-07-31T08:15:21Z")

</div>

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)?  
thanks

---

<div class="post-metadata">

**Author:** ![mks57](https://avatars.discourse-cdn.com/v4/letter/m/b9bd4f/32.png) [@mks57](https://boards.straightdope.com/u/mks57)\
**Post date:** [July 31, 2007, 8:22am UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/2 "2007-07-31T08:22:26Z")

</div>

Try “dir” from the command-line.

[http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/dir.mspx](http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/dir.mspx)

---

<div class="post-metadata">

**Author:** ![chrisk](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@chrisk](https://boards.straightdope.com/u/chrisk)\
**Post date:** [July 31, 2007, 10:10am UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/3 "2007-07-31T10:10:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Napier](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Napier](https://boards.straightdope.com/u/Napier)\
**Post date:** [July 31, 2007, 10:22am UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/4 "2007-07-31T10:22:45Z")

</div>

dir _._ | text.txt

---

<div class="post-metadata">

**Author:** ![essell](https://avatars.discourse-cdn.com/v4/letter/e/34f0e0/32.png) [@essell](https://boards.straightdope.com/u/essell)\
**Post date:** [July 31, 2007, 10:38am UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/5 "2007-07-31T10:38:55Z")

</div>

[QUOTE=Napier]  
dir _._ | text.txt  
[/QUOTE]

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”_

---

<div class="post-metadata">

**Author:** ![LSLGuy](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lslguy/32/5813_2.png) [@LSLGuy](https://boards.straightdope.com/u/LSLGuy)\
**Post date:** [July 31, 2007, 12:31pm UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/6 "2007-07-31T12:31:19Z")

</div>

[QUOTE=essell]  
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”_  
[/QUOTE]  
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.

---

<div class="post-metadata">

**Author:** ![Rhythmdvl](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Rhythmdvl](https://boards.straightdope.com/u/Rhythmdvl)\
**Post date:** [July 31, 2007, 1:25pm UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/7 "2007-07-31T13:25:48Z")

</div>

Something I find very handy to have done:

[How to add the Print Directory feature for folders in Windows XP](http://support.microsoft.com/?kbid=321379) (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.

Rhythm

---

<div class="post-metadata">

**Author:** ![Dante](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dante/32/9673_2.png) [@Dante](https://boards.straightdope.com/u/Dante)\
**Post date:** [July 31, 2007, 1:26pm UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/8 "2007-07-31T13:26:10Z")

</div>

Give [LS - File List Generator](http://www.snapfiles.com/get/lsfilelist.html) a go. There’s ways to do it through MS-DOS, but I’m not sure about your familiarity with DOS commands.

---

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [July 31, 2007, 2:37pm UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/9 "2007-07-31T14:37:55Z")

</div>

[QUOTE=Rhythmdvl]  
Something I find very handy to have done:

[How to add the Print Directory feature for folders in Windows XP](http://support.microsoft.com/?kbid=321379) (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.

Rhythm  
[/QUOTE]

Well absolutely great ☹ 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.

---

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [July 31, 2007, 2:51pm UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/10 "2007-07-31T14:51:11Z")

</div>

[QUOTE=Rhythmdvl]  
Something I find very handy to have done:

[How to add the Print Directory feature for folders in Windows XP](http://support.microsoft.com/?kbid=321379) (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.

Rhythm  
[/QUOTE]

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”  
exit  
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?

---

<div class="post-metadata">

**Author:** ![Frank](https://avatars.discourse-cdn.com/v4/letter/f/3d9bf3/32.png) [@Frank](https://boards.straightdope.com/u/Frank)\
**Post date:** [July 31, 2007, 3:09pm UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/11 "2007-07-31T15:09:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fishbicycle](https://avatars.discourse-cdn.com/v4/letter/f/aeb1de/32.png) [@fishbicycle](https://boards.straightdope.com/u/fishbicycle)\
**Post date:** [July 31, 2007, 3:19pm UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/12 "2007-07-31T15:19:38Z")

</div>

I’ve been using [Karen’s Directory Printer](http://www.karenware.com/powertools/ptdirprn.asp) for several years. It’s handy, and it’ll make a text file of whatever attributes you select. And it’s free.

---

<div class="post-metadata">

**Author:** ![Rhythmdvl](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Rhythmdvl](https://boards.straightdope.com/u/Rhythmdvl)\
**Post date:** [July 31, 2007, 3:52pm UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/13 "2007-07-31T15:52:40Z")

</div>

[QUOTE=OldGuy]  
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”  
exit  
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?  
[/QUOTE]

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!

---

<div class="post-metadata">

**Author:** ![Napier](https://avatars.discourse-cdn.com/v4/letter/n/ce73a5/32.png) [@Napier](https://boards.straightdope.com/u/Napier)\
**Post date:** [July 31, 2007, 3:53pm UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/14 "2007-07-31T15:53:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![scm1001](https://avatars.discourse-cdn.com/v4/letter/s/c4cdca/32.png) [@scm1001](https://boards.straightdope.com/u/scm1001)\
**Post date:** [August 1, 2007, 2:05am UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/15 "2007-08-01T02:05:50Z")

</div>

[QUOTE=fishbicycle]  
I’ve been using [Karen’s Directory Printer](http://www.karenware.com/powertools/ptdirprn.asp) for several years. It’s handy, and it’ll make a text file of whatever attributes you select. And it’s free.  
[/QUOTE]

just what I was looking for - thanks

didnt really want to mess around with DOS or shell commands

---

<div class="post-metadata">

**Author:** ![SlickRoenick](https://avatars.discourse-cdn.com/v4/letter/s/e68b1a/32.png) [@SlickRoenick](https://boards.straightdope.com/u/SlickRoenick)\
**Post date:** [August 1, 2007, 3:00am UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/16 "2007-08-01T03:00:07Z")

</div>

[QUOTE=OldGuy]  
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”  
exit  
[/QUOTE]

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

---

<div class="post-metadata">

**Author:** ![633squadron](https://avatars.discourse-cdn.com/v4/letter/6/ee59a6/32.png) [@633squadron](https://boards.straightdope.com/u/633squadron)\
**Post date:** [August 1, 2007, 3:37am UTC](https://boards.straightdope.com/t/simple-way-of-getting-a-text-file-of-a-folders-contents-pc/413793/17 "2007-08-01T03:37:12Z")

</div>

[QUOTE=SlickRoenick]  
What does the %1 do? And what do the switches /-p, /w, and /p mean?  
[/QUOTE]

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.
