Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I get a text list or data dump of filenames from a Windows directory? I have the following folder set up:

[My Documents]

I want to get all the file names of the files that are inside the folder (My Documents) in just one process, and make the filenames as a list that I can copy to Notepad.

Currently my process is to hit F2 to highlight the filename of the file and hit CTRL+C to copy and paste it into Notepad, then stack it to the list. I want to be able to get those filenames in a fast and easy way.

I want to avoid any external software if possible; I just want to utilize the software that is installed on my laptop (Office and Windows XP, though Vista or Windows 7 wouldn't be too bad to know).

share|improve this question
up vote 7 down vote accepted

Open command prompt.

cd %homedrive%%homepath%\My Documents

dir /b > filenames.txt

filenames.txt will contain a list of all your files.

share|improve this answer
You're awesome dude. works like charm! thanks! – Pennf0lio Dec 3 '10 at 4:12
@Pennf0lio you're welcome! – Sathya Dec 3 '10 at 4:18

Open powershell and type the following:

PS> cd "~\My Documents"
PS> ls | Where-Object {!($_.PSIsContainer)} | foreach-object {add-content -path filelist.txt -value $}

What happens here is you ls (list) all the files in the directory and send that list through a filter that removes directories (where-object is not a container). Then you send the filtered list to a loop that adds the file names to your txt file one at a time. $_ represents an object in the list.

You can do all kinds of other cool stuff with this like adding -recurse onto the ls command, which would give you all files in all directories under the current directory.

You can replace $ with $_.fullName to get the full path, or $_.Extension for the extension. See the documentation for the fileinfo class in msdn to see all the cool stuff you can do with a fileinfo object.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .