Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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]
--SomeFileName.doc
--AnotherFileName.bmp
--AnotherMoreFileName.zip
--...

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
add comment

2 Answers 2

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
add comment

Open powershell and type the following:

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

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 $_.name 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.