How do I copy all file names in a folder to notepad?

I often want to copy all the file names with full path and extensions in a folder to a ".txt" document but can't. Is there an easy way to do this? How? Is there a simple batch file that will do it? Freeware might work, but I would rather have a simple batch.bat or .exe file that works.

 

Question Info


Last updated December 9, 2018 Views 293,559 Applies to:
Answer

I often want to copy all the file names with full path and extensions in a folder to a ".txt" document but can't. Is there an easy way to do this? How? Is there a simple batch file that will do it? Freeware might work, but I would rather have a simple batch.bat or .exe file that works.

 

The syntax given by Steve Cochran will work but I would like to add a few comments.

First of all, the wildcard (*.*) is not needed -- the 'dir' command assumes all files & folders so it's sort of redundant in my opinion to type the wildcards.  If you choose to do so, it will not hurt anything.

Secondly, there is a way to sort the output in alphabetical order; for that the /o switch is needed.  I only mention this because, invariably whenever people ask for this kind of stuff they intend to do something with the filenames and it's much easier to deal with it if it's sorted. Another switch that I use is '/b'.  The /b switch will remove the heading information & summary so that you get just the file names.  What I normally do is:

dir "C:\some folder" > output.txt /b /o

Notice that the path for the folder name is wrapped in quotes.  You use quotes whenever the folder name or file name has a space in it.  You will also notice that there is just a single (>) as opposed to the two (>>) in Steve's answer.  The difference is that the former will overwrite the contents and the latter will append to the existing file named "output.txt".

Finally, I use the 'Open command window here' shortcut so that I don't have to navigate to the folder/directory that I want to work in.

For example if you wanted to get an output of the following folder, C:\Users\{username}\Pictures\Summer Vacation

Navigate to that folder in Windows Explorer. Hold down the shift key and RIGHT click on Summer Vacation folder.  You will see a new option called 'Open command window here'.  This way, you don't have to type the full path in your dir command.

161 people were helped by this reply

·

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.

Answer

© ウィンドウズスクリプトプログラマ - Windows Script Programmer

on explorer, select all, shift + right click, copy as path. paste on notepad.

in command prompt, enter

hoge.cmd folder_path

(for %%1 in ("%~f1\*") do @echo %%1) > fullpath_hoge.txt

or drop folder on hoge.cmd

'> fullpath_hoge.txt' can be '| clip.exe'

or shortcut in sendto folder.

cmd.exe /c for /l %n in (1,1,2) do if %n==2 ((for %q in (%x%) do @for %r in ("%~q\*") do @echo %r)|clip.exe) else set x=

93 people were helped by this reply

·

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.