How to Copy File Names to Excel using CMD


Do you work with a lot of files? I do. And it’s hard and tedious to keep everything organized. An easy way to keep tabs on each file  is to copy all the file names into an Excel sheet and use that to keep tabs of the files as they go through our transcription workflow.

Now before we jump into CMD, you’ll need to know 2 CMD commands: CD and DIR.  

CD is short for Change Directory. This is the command you’ll use to navigate through directories, also known as folders, in a drive.

DIR  is short for directory, and is used to display information about contents of the current directory. In windows terms, the contents of the current folder.

With that out of the way, let’s me show you how to copy file names into excel using CMD.

Step 1: Open Command Prompt (CMD)

Click on windows search or Cortana and search for Command Prompt or CMD. Command Prompt will show up in the search results. Click on it to launch or press enter. You can also launch CMD from the Run command: simultaneously press the windows + r keys and then type CMD and click okay or press enter.

Step 1: Open Command Prompt (CMD)

Step 2: Navigate to the Folder

Open Windows Explorer and navigate to the folder that contains the files. Click on the address bar to reveal the folder path. Note the drive letter (we’ll need it in Step 3), in this case it’s G, and then copy the folder path (we’ll use it in Step 4).

Step 2: Navigate to the Folder

Step 3: In CMD Navigate to the Drive

Head back to command prompt and type the drive letter and a colon. This is the drive you noted in Step 2. The drive that contains the folders that contains my files is drive G. So I’ll type G, colon.

So here’s my code:

C:\Users\Iman> g:

Then hit enter.

This is how you navigate to drives in CMD. Type in the drive letter, colon, and hit enter.

Step 3: In CMD Navigate to the Drive

Step 4: In CMD Navigate to the Folder

Now that we are in the right drive, let’s navigate to the folder that contains the files. We’ll use the change directory command.

So type CD, space, then right click with your mouse. Right clicking with your mouse pastes the folder path that we copied from the Windows Explorer in Step 2.

Here’s my code after pasting the folder path:

C:\Users\Iman> g:
G:\ cd G:\Audio-Files 

Press enter. And you have successfully navigated to the folder that contains your files.

Step 4: In CMD Navigate to the Folder

Step 5: Type the DIR Command

We are going to use the DIR command, which displays the contents of the folder, to display the contents of the folder in Excel. So we type the dir command, and then tell it where to post the output. That’s achieved by typing a space, greater than sign, then the name of the output file. CMD will automatically create this file in the current folder.

I’m going to name my Excel file list.xls. You can change the .xls extension to .txt or .doc and the DIR command will save the file into a Notepad and Word documents respectively.

Here’s my code:

C:\Users\Kongo> g:
G:\ cd G:\Audio-Files 
G:\Audio-Files> dir > list.xls

There are a number of attributes that you can add to the DIR command to suite your preferences.

For instance, if you need just the only the filenames you can use:

DIR/B  > [filename.xls]

You can sort the filenames alphabetically:

DIR/B/O:N  > [filename.xls]

And include all the names of the files in subfolders:

DIR/B/O:N/S  > [filename.xls]

Remove the directory path:

DIR/B/A-D/ O:N/S  > [filename.xls]

Finally, save the Excel file in a different folder:

DIR/B/A-D/ O:N/S  > [folderpath\filename.xls]

Step 5: Type the DIR Command

Here is a list of attributes you can use:

/A      Displays all files with specified attributes.

attribs   D  Directories   R  Read-only files         H  Hidden files

S  System files  A  Files ready to archive  –  Prefix meaning “not”

Several attributes may be combined e.g. /A:HD-R

/O      Lists files in sorted order.

N  By name (alphabetic)       S  By size (smallest first)

E  By extension (alphabetic)  D  By date & time (earliest first)

G  Group directories first    –  Prefix to reverse order

Several attributes may be combined e.g. /O:GEN-D

/S      Displays files in specified directory and all subdirectories.

/B      Uses bare format (no heading information or summary).

/L      Uses lowercase.

Here’s a short video tutorial:

That’s it for this post. And here is another great post on how to rename your files using powershell.


41 responses to “How to Copy File Names to Excel using CMD”

  1. moncler scontati Avatar

    Thank you very much. This really helped me with my work. I appreciate your help. Thanks a lot.

    1. Johny B Avatar

      very much helpful.. thnx a lot 🙂

      1. Kongo Avatar

        My pleasure.

  2. Anil Pandey Avatar

    Really great thing dear. You are awesom.

    BR
    Anil Pandey

    1. Kongo Avatar

      My pleasure Anil, glad you found the post useful.
      All the best.

  3. Vivek Avatar

    Thanks for the wondferful post…Saved hours for me …

    1. Kongo Avatar

      Thanks Vivek, always a pleasure.

  4. shankar Avatar

    thank you Saved hours for me

  5. Paul Corthouts Avatar

    Do you know how to do this trick on a Mac?
    “Copy all File Names in Folder to Excel”
    You have no idea how much this would help a bunch of people that I know!!! I’m videographer since 1988 and it’s a huge work to archive all my footage now that we transfer everything to digital.

    1. Kongo Avatar

      Sadly I don’t. But I am sure someone that knows their way around mac’s terminal can figure it out. From what I remember it is very similar to cmd…Sorry I couldn’t be of more help Paul.
      Btw I am scripting a software that can perform this trick for you. I’ll see if I can easily create a Mac version…

      1. Kongo Avatar

        … A good friend, who uses a Mac on a more regular basis than I do, tells me this is relatively easy to accomplish natively. Step 1. Select all the files you want to copy the names to Excel on OSX. Step 2. Choose Edit > Copy. Open TextEdit and Paste. Then copy and paste the names from TextEdit to Excel or Numbers. And that’s it. Not sure this will work with sub-folders though.

        Let me know if that helps.

        1. dilip Avatar

          Sir, i want to learn CMD Command language

          1. Kongo Avatar

            Try Udemy.com It has a lot of great courses on CMD command language.

  6. Waqqar Ahmad Avatar

    Amazing, Worked perfectly
    Thanks a bunch

  7. Nania Avatar

    Good day, I have a folder with over 10 000 songs on, would like to copy all the song names and all the other info as well, like artist name, album etc, to an excel spreadsheet. All the info on the web only allows me to copy the song name (first column of a windows folder) but not the rest of the columns, do you maybe have an answer?
    Thank you!

    1. DanJPet Avatar

      I have the same issue. Exactly same. Any help Kongo?
      BTW, I dont know DOS, but is this possible?

      1. Kongo Avatar

        It is possible using PowerShell, which is more powerful than Command Prompt and worth learning.
        Check out this post: https://devblogs.microsoft.com/scripting/list-music-file-metadata-in-a-csv-and-open-in-excel-with-powershell/
        All the best.

  8. neworldwebsites Avatar

    thanks for jobing that 😉

  9. Shruti Avatar

    This worked wonderfully. Thanks!

  10. Stephen Avatar

    dir /s /b: generates a list of all folder paths and file paths. Is there a way to filter out folders from that list, so only filepaths are extracted?

    1. Kongo Avatar

      Stephen, I don’t know how to do that in CMD.
      If anyone else does, please chip in.
      But it’s easy enough to remove the folder paths in Excel, using find or replace or converting the text into columns and deleting the folder path columns.
      Hope that helps.

  11. sixdiamonds Avatar

    Thank you very much….this saves a lot of time….I am not new to MS-DOS but I lost touch with it…. Thanks to your post, It felt good using DOS commands.

    1. Kongo Avatar

      Yeah, it does. Love DOS, and use it all the time. The ping command is great for troubleshooting my network connections, and I use the cipher command to delete sensitive data…

  12. Amne Avatar

    Thank you for the solution.

    1. Kongo Avatar
  13. David Avatar

    I googled this issue, expecting to find a tool of some sort to do it.
    Of course, I should have realized, Windows is just DOS…
    beep boop assuming manual control

  14. Keegan R Avatar

    Super helpful! The only thing I had to look up to add to this was how to do this for a network drive. I just added the network path to the end and it worked like a champ. dir /o:S “\\network\drive\here” > filenames.txt

  15. Nerissa Avatar

    thanks a lot, this is so useful, especially when I keep forgetting what files I have got on which drive!
    my only question is, not all file names are written in English. Some of them are written in Japanese, some in Chinese and some in other characters. Is it possible that the proper names can be shown, rather than ???????
    thanks!

    1. Kongo Avatar

      Try and change the CMD console font to NSimSun font or SimSun-ExtB, that should render the Chinese/Japanese characters.

  16. Burak Avatar

    Did wonders but it created the file.txt in the folder I was working on instead of the Users folder.

    Thanks a lot. this saved a ton of trouble.

    1. Kongo Avatar

      My pleasure. You can set the filepath where you want the txt to be saved…, by default it saves the file in the same folder.

  17. Javier Avatar

    I can’t believe this post is 7 years old. I’m in Argentina, and downloading a ton of pdf invoices with key data on the filename. Googled it, and this is the first search result. If I could, I’d post a screenshot of how big this shows with the step by step. Great work. Congrats, and thanks a lot.

    1. Kongo Avatar

      Javier, it was a pleasure to share the knowledge. I learned this trick in 1996, when I got interested in computers and we didn’t have Windows, only MS-Dos.

  18. Sourabh Maheshwary Avatar

    This is so helpful!! Thank you so much for making it so easier and good explanation!

    1. Kongo Avatar

      My pleasure.

  19. Shivani Asati Avatar

    Thanks alot. I was really helped alot

    1. Kongo Avatar
  20. Pero Avatar

    THANK YOU, this worked flawlessly and faster than any other method Ive tried!

    1. Kongo Avatar
  21. John Avatar
  22. jr Avatar

    DUDE…… Thank you.

Leave a Reply

Your email address will not be published.

41
0
Would love your thoughts, please comment.x
()
x