How to copy names of files from a window's folder

Imagine you have 100 excel files in your windows folder (or even 100,000) and you need to write names of those files in your SAS syntax (or any statistical software programs).  Typing 100 names is time consuming.  Instead you can use a cmd prompt at Windows and copy file names into a text file.

On Windows (7 in my case)

START --> RUN ..

Type in "cmd" in the pop-up window and OK it.

You get a small black window.  Type "cd" at the prompt to get  to the folder you want to go.


  • cd Music  (You will go to a folder Music;but this folder has to exist in the folder you are currently in)
  • cd C:\temp (This will directly let you go to the folder you want to go regardless of where you are currently in the holder structure; I used an example of C:\temp)
  • cd .. (You go up one folder structure)

Once you get to the folder, you will do this (this is an example of getting text files that have extention "txt" e.g., abc.txt).

dir *.txt > example_of_cmd_text.txt

This will copy all files that end with extention ".txt" into a text file.  The resulting text file will include all file names in the folder.  This is an example:

It comes with additional pieces of information you may not need (e.g., date), so you want to open this with Excel and get exact information you need.

I googled for CMD commands tutorials:

Leave a Reply