Tech Xpress

Copy all Filenames in a Directory to a Text File

Got to know this last week! This works great if you want to save all the filenames in a directory to a text file.1. Open up your command prompt by typing cmd in the run dialog box and hitting Enter.
2. Navigate to the directory which has the files and type the following command -
DIR /B /O:N > filename.txt
This will save all the filenames in the current directory to a text file. The text file will be saved in the same directory.
3. To save file names from any sub-directories in the current folder, just add /S like -
DIR /B /O:N /S > filename.txt

That's all!
posted by Vijeesh Ravindran, Thursday, November 13, 2008


123 Comments:

Comment by Anonymous Anonymous on December 19, 2008 at 8:48 AM  
WORKED LIKE A CHARM !!!
BIG THANKS
Comment by Anonymous Anonymous on January 19, 2009 at 4:11 AM  
<3 PERFECT
Comment by Anonymous Anonymous on March 7, 2009 at 2:00 AM  
Just what I needed, thanks!
Comment by Anonymous Anonymous on March 11, 2009 at 3:00 AM  
Nice one, thanks!
Comment by Anonymous Anonymous on April 1, 2009 at 2:18 AM  
The fastest way to get the DOS Prompt to your directory is to first, find it in the windows explorer, then select and copy the address from the address bar in Explorer.
In the cmd window type 'c: ' then right click and select paste from the menu.Now that you have your directory address just hit enter to go directly to your directory without typos.
Ctrl-V will NOT paste in the CMD window.
Comment by Blogger Adam on May 14, 2009 at 8:10 PM  
Awesome tip! Worked like a charm.
Comment by Anonymous Jay on June 23, 2009 at 5:29 AM  
Thanks mate. Exactly what i needed.
thanks a lot!!!!!
Comment by Anonymous Anonymous on August 21, 2009 at 3:41 PM  
Thanks dear..... loved it even if didn't understood the working.
Comment by Anonymous Anonymous on October 16, 2009 at 5:47 AM  
I've been looking for this for a long time. I thought I'd have to learn C or something, and then you show it's just a simple DOS prompt. Good job. Thanks for sharing!
'C:\Users\Elvis\Desktop\Original_images\Old' is not recognized as an internal or
external command,
operable program or batch file.
@Elvis - If you mean to navigate to that directory, use the cd command followed by the the directory location.
Comment by Anonymous Anonymous on November 28, 2009 at 12:49 PM  
I'm getting the same error. What is the cd command? Can you show an example of exactly what this looks like for a folder on your computer please? Thanks so much!
Comment by Anonymous Anonymous on January 20, 2010 at 8:52 PM  
the CD command is CD, prepend that to the directory. add the /d parameter if you want to change drives. now back to changing this Civ2 scenario so it will work with ToT.
thanks my dear guru. I been long time searching for this commonad i thought to learn some programming languagges. I am very happy


thanks a lot my dear guru
thanks very my dear guru. I am very happy now
beautiful! thanks a ton!
i was wondering if any one could point me to a repository of all these wonderful tricks...
thanks guys :)
Comment by Anonymous Anonymous on March 24, 2010 at 11:13 PM  
DIR /B /O:N /S > filename.txt
--
THIS WORKS FINE..HOW TO SAVE FILENAME AND FILESIZE TO A TEXT FILE./
Wow- I can't believe I got to use the C prompt this morning! Makes me feel warm an fuzzy to use DOS. Thanks for the advice- perfect!
Much obliged for posting this! Worked like a charm...I was able to make an excel report out of the 2K plus filenames the list generated and compare the data to my existing database. You definitely saved me a lot of time and trouble!
Is there a way to copy all file names from an external drive?
@Scooter - the above tip should work for external drives too. You would just need to navigate to the folder in your external drive through dos.
Comment by Anonymous Anonymous on April 13, 2010 at 10:01 PM  
I'm trying to navigate to an address on the M drive (a server drive) and I get "The filename, directory name, or volume label syntax is incorrect." Any help?
I could'nt get this to work either, but found a freeware program that works perfectly. It adds an option when you right click to "Copy filenames to text"
Perfect solution. Just found it today, and it works in windows 7, and with 64 systems.

http://www.extrabit.com/copyfilenames/

hope that helps.
You are a star!!!

Thank you
THANK YOUUUUUUUUUUUUUuuuu

U R GR88888888888

wooooooooooooooooooooooooooo
That was indeed helpful. Is there any way that it can list it in the same order it looks, rather than keeping it in the alphabetical order? Please help...
Does anyone know a way to copy every file name in a folder to its own text file? What I mean is that rather than creating a single huge list of all the files in a directory, there would be new text files, each containing one of the names of the files in the directory.

Thanks so much in advance
Comment by Anonymous Anonymous on August 22, 2010 at 4:12 AM  
Thank you Nick for sharing wiht us the 'copyfilenames' software. It is a BIG help - so much easier than using cmd.
Comment by Anonymous Anonymous on September 2, 2010 at 2:06 AM  
Works great thank you!
Comment by Anonymous Anonymous on September 22, 2010 at 5:12 PM  
I use Flash Renamer to copy the files in a folder. Just open the folder in flash renamer, then copy the list into notepad, excel or calc. You've also got the added bonus of being able to rename them if you wish. It's free to use as a trial, however the more files you actually rename, the longer it takes the software to load. http://www.rlvision.com/flashren/about.asp
Comment by Anonymous Sreekumar on October 2, 2010 at 2:48 AM  
Amazing command.... the easiest way... i have ever seen
Really good and helpfull, saved my time
Comment by Anonymous Anonymous on November 9, 2010 at 12:42 PM  
Simple and most useful...!
Thanks buddy.
Cannot seem to get this to work... have tried the commands you have suggested, even tried the following:

D:\MMB Folder\MY SCRAP KITS ZIPFILES\PAY SCRAPS /B /O:N > list.txt

and it tells me: 'D:\MMB' is not recognized as an internal or external command, operable program or batch file.

However the "D" drive is my spare (internal) Hard drive and where the files are that I am trying to copy.

Please advise?


Chelle in OKC
WillowRavenSpirit@gmail.com
@WillowRaven - Here are two steps for you. Open the command prompt and type the commands mentioned in the steps below.

Step 1 -
CD D:\MMB Folder\MY SCRAP KITS ZIPFILES\PAY SCRAPS

Step 2 -
DIR /B /O:N > list.txt
Why you don't just take that small program that 'nick' told about. I took it and it is a BRILLIANT! Thanks mate!

Comment by nick

I could'nt get this to work either, but found a freeware program that works perfectly. It adds an option when you right click to "Copy filenames to text"
Perfect solution. Just found it today, and it works in windows 7, and with 64 systems.

http://www.extrabit.com/copyfilenames/
Comment by Anonymous Anonymous on March 11, 2011 at 1:21 AM  
Nick,

Copyfiles is incredible!!!

Thanks from Holland
Comment by Anonymous Anonymous on March 21, 2011 at 11:25 PM  
Outstanding.. Been trying to figure this one out without having to download 3rd party programs for a few hours now. Many Thanks Friend!
Comment by Anonymous Anonymous on March 25, 2011 at 2:32 PM  
Perfect, thank you so much for sharing!
Rosi:)
Comment by Anonymous Anonymous on April 1, 2011 at 1:39 AM  
Thanks A TON!!!!...
This simple command but was great help. Please post a command to do the same in UNIX
Comment by Anonymous Anonymous on April 12, 2011 at 5:38 PM  
Thank you, it saved my time, very helpful. Thanks again.

from VietNam.
It really works. great.Thanks
Comment by Anonymous Avanish Sharma on May 3, 2011 at 7:01 PM  
Awesome :) looking for this for a long time :) thanks a million :)
Comment by Anonymous Giurgiu Luigi on May 29, 2011 at 12:38 PM  
Excelent! Thanks a lot!
Huhu.. It works and rock.. TQVM!
Comment by Anonymous Anonymous on June 8, 2011 at 3:44 PM  
i realy work thanks
Comment by Anonymous Anonymous on June 15, 2011 at 8:25 PM  
Very nice. If you don't want the directory to appear you can do:
dir /B /O:N /S /A:-D > filenames.txt
Comment by Anonymous Rob on June 21, 2011 at 2:08 PM  
Super cool. Thanks.
This just saved me a lot of time.
Comment by Anonymous Ankush on June 24, 2011 at 1:42 PM  
Thanks a lot for your post. Simple and quick.
Comment by Anonymous Anonymous on June 30, 2011 at 5:02 AM  
works great! thank you
Comment by Anonymous Anonymous on June 30, 2011 at 7:43 PM  
since my directory had a very long location to type, I found it easier to simply paste the entire directory chain into a browser (chrome). It then listed all of the files, and I could highlight and copy.

=)
PowerChordWebDesign.com
Comment by Blogger sagar on July 7, 2011 at 2:49 PM  
good Trick.. :)
Comment by Anonymous Derik on July 8, 2011 at 8:35 PM  
Thanks for the to the point and informative post!
Comment by Anonymous Anonymous on August 5, 2011 at 1:54 AM  
You are some kind of superhero.
Comment by Anonymous Anonymous on August 11, 2011 at 8:21 AM  
Great thx v.much...

But how to take the full HDD directories and folders? not just the directory that i go to it?
Ex: I have a picture folder called "pic" i do:
C:\pic>dir/b/o:n/s>abc.txt
work as charm...
when I do:
C:\dir/b/o:n/s>abc.txt
it gives me "Access is denied"...
so is there a way to get all my C: dir, subdir, and folders?
Comment by Anonymous Anonymous on August 11, 2011 at 8:37 AM  
Hi again, I just do it, I get all my C: drive directories,subdirectories, and files, to the txt file.

I do:

C:\dir/b/o:n/s c:>aaa.txt

(space only between /s and C: )
but it give me on some files
"file name is too long" ..if there is a way to take too long files name too?

I'm using windows Vista.(it takes minutes)..and the output txt file size is 95MB for me :).
Comment by Anonymous Anonymous on August 13, 2011 at 1:26 AM  
I put this in a batch file (text file saved as .bat) and copied the batch file to the directory I wanted to copy the file names from, and it works.....
This keeps you away from DOS window, if you are not comfortable working with DOS.
Good job.
WOW! I really thought I was going to have to C&P every file! Thanks a LOT for this, much appreciated!
I have never read such a wonderful article and I am coming back tomorrow to continue reading.
www.pcs4cheap.ca
Comment by Anonymous MKG on August 31, 2011 at 6:28 PM  
Its great --copying file names to a folder.
If it Can bring the size of the files too it would be wonderful.
Thanks a lot
Comment by Anonymous Saif on September 18, 2011 at 4:07 PM  
Thanks a lot :)
Comment by Anonymous Anonymous on September 30, 2011 at 4:07 AM  
Magic :)
Comment by Anonymous Anonymous on October 12, 2011 at 11:17 PM  
It was a simple and great technique.Thanks!
Comment by Anonymous Anonymous on October 26, 2011 at 5:32 PM  
Thank you very much!!
Niice! Thanks a lot. This was a big help with organizing references for a Journal Article.
Comment by Anonymous Anonymous on December 7, 2011 at 12:07 PM  
Thanks a lot,
u saved my time
Comment by Anonymous Anonymous on December 10, 2011 at 6:54 AM  
worked great - thanks very much
Comment by Anonymous Anonymous on December 21, 2011 at 11:45 PM  
Just adding my comment to the "Cheers, mate!" variety. Much appreciated!
Comment by Anonymous Afshin on December 24, 2011 at 5:24 PM  
Thank you veryyyyyyyyy muchhhhhhhh
thank you very much, and also I need to know how to remove the filename extension. it is possible send a mail to me sankar.a@ilink-systems.com
Comment by Anonymous Anonymous on January 10, 2012 at 6:10 PM  
its possible capture to a text file only the names of the files (excluding the names of the folders) in a folder and subfolders but without the path of the files?
I have been trying to do this at hours without success because after adding the s the complete path is added.
please help
Comment by Anonymous Anonymous on January 11, 2012 at 2:38 AM  
for filenames only:

dir /B > filename.txt

I don't know of a way to include the subs also, except the way that includes the full path
Thanks, man. That saved me loads of time! All the best for you!
Comment by Anonymous Akber on January 18, 2012 at 1:13 PM  
you are awesome!
Perfect. Thanks.

- Justin
Florida Department of Environmental Protection
Comment by Anonymous Anonymous on February 10, 2012 at 12:58 AM  
cool..thanks
Comment by Anonymous Anonymous on February 15, 2012 at 10:14 AM  
didn't expect it to work at first, tank you man! it helped a lot.
Perfect. Just what I needed. Thanks a ton.
Comment by Anonymous Anonymous on March 13, 2012 at 9:25 PM  
This is all I wanted! Good Job, and of course, Thanks a ton!!
Thankks for your gud help.. cheerz...:)
Comment by Anonymous Sandeep on March 23, 2012 at 12:02 PM  
You saved me atleast 2 hours. Thanks a ton.
Cheers
Comment by Anonymous Anonymous on April 5, 2012 at 11:17 PM  
THX!
Thanks so much! It beats using F2 to copy and paste all of the names. Thanks!
Comment by Anonymous Anonymous on May 9, 2012 at 7:15 AM  
Wow!! You're Superb! thanks!
Comment by Anonymous Anonymous on May 15, 2012 at 3:03 PM  
cool thanks man I copied 4562 file name to word an to excel
Comment by Anonymous Fetter on May 31, 2012 at 5:49 AM  
Worked just as I needed it. THanks!
Comment by Anonymous Anonymous on June 2, 2012 at 9:23 PM  
You Rock!.

Thank you..
Comment by Anonymous Anonymous on June 8, 2012 at 4:22 PM  
I got tired of doing the DOS thing so I wrote my own Windows program to do this task. I can email this program to you and the source code if you like.

chrisk@bell.co.za
Comment by Anonymous Anonymous on June 14, 2012 at 9:35 AM  
not trying to advertise for this product but I myself am looking for a better solution after trying the DOS method.
I actually tried this freeware and it worked like a miracle :D

http://www.extrabit.com/copyfilenames/
Comment by Anonymous Anonymous on June 26, 2012 at 3:08 PM  
Thank you!!!!
u are AWESOME!!!
:D
Comment by Anonymous Anonymous on July 9, 2012 at 1:22 PM  
Thanks, It's work!!
Comment by Anonymous Anonymous on July 18, 2012 at 4:37 AM  
Dear Masters of DOS,
I used these fantastic commands and loved it.
But I'd like to get my list of files SORTED by types and by alphabetic order.
All the 'avi', then all the 'jpg', then all the 'txt', etc
Do you think that possible to write it down?
Many thanks in advance!
Comment by Anonymous Anonymous on July 18, 2012 at 12:14 PM  
Hello,
this works great.
But how to modify it to get ONLY (as exemple) all 'jpg' files or all 'doc' files listed?
Thank you for your help.
Comment by Anonymous Anonymous on July 18, 2012 at 7:25 PM  
It Really Works!!!!!!!!!!!!! Thanks
Comment by Anonymous Anonymous on July 20, 2012 at 1:21 AM  
First, Thanks for such a Cool Tip which I have been looking.

Second, it can also generate Excel, Word or Xml files, Just Change the Extension form .txt to
.xls (For Excel), .doc (For Word)
and .xml etc in the same directory.
Comment by Anonymous John on August 4, 2012 at 3:21 AM  
I get the prompt "File Not Found"

I don't understand anything about directories or CMD prompt. The file I want the file names from is in the directory C:\Folder
How does this apply to me?
Comment by Anonymous Anonymous on September 13, 2012 at 2:01 PM  
Thanks, works great
Comment by Anonymous AttilaNab on September 25, 2012 at 2:32 PM  
Hello. i was also having the same issue but Long Path Tool helped me in this situation. You can see here PathTooDeep.com. It might help you.
Thanks and Regards,
Attila
Comment by Anonymous Ruthie on October 6, 2012 at 11:59 PM  
Vijeesh you are a life saver! I've wondered if there was an application for this for several years and just went without. I haven't had the opportunity to use CMD for much in years...had forgotten most DOS relevant stuff...so also thank you to the couple people that helped with directory syntax. I too am reluctant to download a third-party application, especially to do something this simple, so THANK YOU so VERY much!!!
Comment by Anonymous Anonymous on October 15, 2012 at 11:46 AM  
thanks so much working grt.
Comment by Anonymous Anonymous on November 2, 2012 at 6:59 AM  
Awesome tip - good on ya!
Thank you, it worked. Simple and fast.
Comment by Anonymous Anonymous on November 26, 2012 at 12:16 PM  
Thanks a lot. Any idea how to insert the name of hidden folders also?
Comment by Anonymous Anonymous on December 31, 2012 at 1:35 PM  
It's Great
Thanks :)
Comment by Anonymous Sajin on January 4, 2013 at 10:29 AM  
Thumps Up!
Comment by Anonymous Anonymous on January 7, 2013 at 2:24 PM  
What we do if we dont want directory names but we want only file names list?
Note: dir /B /O:N /S /A:-D > filenames.txt DOES NOT WORK!
i use firefox...paste path in address bar.. ex.D:\Movies..firefox will display all contents in that directory. right click copy all, select all and paste into notepad..or text editor.. very simple..YESSIR
@Michael Mackey
THANKS! I used to MS DOS method but could not get it to work for any drive other than the "C:" drive. I'm almost embarrassed that I didn't think of your method myself :-)
Comment by Anonymous Anonymous on February 4, 2013 at 11:03 PM  
@Michael Mackey
That works, thank you! Though I went and downloaded Copyfilenames, as this comes up often enough for it to be worth it to me. It's even easier to select all files and right click to have it in your clipboard.
Comment by Anonymous Anonymous on February 6, 2013 at 12:54 AM  
Thanks! Saved me a bunch of time today :)
Thanks a lot...
Keep that Good Work Up...
Comment by Anonymous Anonymous on February 17, 2013 at 6:13 PM  
PERFECT!!!
Comment by Anonymous Albangel on February 18, 2013 at 10:12 PM  
It says access denied. Please help...
Comment by Anonymous Anonymous on March 10, 2013 at 11:55 AM  
Thank you!! This saved me a lot of time.
Or you can just put your cursor at the start of the windows explorer path and type cmd then then it will open a command prompt at the current directory.

example:
--------explorer window----------
cmd C:\someplace\on\my\hardrive
--------address bar ---------
-some files in here
-files files
-files files

--------explorer window----------

This saved me so much time that I thought of sparing a while to thank you! :)
Really helpful, worked perfect using cd comand!
greets!
It's excellent thanks a lot..........
There is a "Windows" way of doing that:
At windows explorer, select the files you want or "ctrl+A" to select all. Then, press SHIFT and right click on the list, and click "copy path".
After that, past it to notepad or wathever.
Comment by Anonymous Anonymous on June 22, 2013 at 1:50 AM  
@ Luciano Cebula...
does it copy path of files from sub-folders also... I dont think so..
Comment by Anonymous Anonymous on July 9, 2013 at 11:07 AM  
Thanks Vijeesh; much obliged. Thanks Luciano. very useful if need only selected files.
Comment by Anonymous K Mec on July 20, 2013 at 5:09 PM  
It is really superb. After downloading and testing lots of software, I was tired. Atlast i came to this and tried..I just want to say it is awesome,great, and speedy than any software that i tested. I have a list of more than 17000 files. It created the list in 5 mins flat. Supert...Big thanks,,thank you.
Comment by Anonymous Kim on September 22, 2013 at 1:42 AM  
Cheers. Helps me a great deal when doing back up of my computer!
I deliberately omit to back up all files to external (movies for instance), but want to have the files names in case my pc crashes.

I've been looking for a substitute ever since the old windows xp days (back then the "log folder" programme was able to do the job).
I tried both the cmd and windows method. Haven't tried the copyfilenames yet.