Wednesday, 4 June 2008

How to save a list of files in a folder

There are a number of programs available that will create a text file from a list of files in a folder, but here is a quick and easy way of doing the same using the Command Prompt.

Firstly, open up the Command Prompt (aka the MS-DOS Box). To do this either click on 'Run' in the 'Start' menu, or hold down the Windows key and press R (the Windows key is the one with the Windows logo on). In the box that opens type cmd, and either click the 'OK' button or press the Return key. The Command Prompt application should open, looking something like this.


Secondly, you will need to navigate to the folder which contains the files you wish to list. If it is on a different drive type the drive letter followed by colon (e.g. D:) and hit return. Then type cd (change directory) followed by the path of the folder, for example:

cd c:\documents and settings\owner\my documents


On some versions of Windows you only need to type part of the folder name and then press the Tab key and the Command Prompt will fill in the rest, e.g. type cd c:\docu and press Tab to change the command to cd c:\documents and settings.

If you do not know the full path of the folder, you can set Windows Explorer to show it in the address bar or title bar - one of my earlier posts explains how to do this (I would recommend showing the full bath in the address bar). You can copy the path from the address bar and paste it into the command prompt screen by clicking on its icon in the top left hand corner, which opens a drop down menu as shown below.


Once you have navigated to the right folder you can type the command to create a file list in that folder in the form of a text file that can be opened in notepad or your word processor.

Note: Windows Vista includes a feature where you can hold down the Shift key and right-click on the icon of the folder you wish to list the files contained within and select 'Open Command Window Here' from the menu that opens. I will be publishing a post soon which will provide instructions on how to add this feature to Windows XP.


Directory List Command

To create a list of all the files in the folder type dir /a-d /b > filelist.txt and press Return/Enter.

The command includes two switches, /a-d and /b. The first of these stops the dir command. from listing folders; the second prevents the command from showing the extra information you see if you just type dir and hit Return. If you wish the text file to have a different name change it from 'filelist' but remember to put '.txt' at the end so that Windows knows that it is a text file.

The dir command has a variety of other switches, the following command will list the names of all the mp3 files in the current folder and all the sub-folders that it contains:
dir *.mp3 /a-d /s /b > mp3filelist.txt

The *.mp3 part tells the command to only list files with that extension, and the /s sets it to list the files in sub-folders too. Note that the files in the sub-folders will be listed prefixed by the folder name, e.g. 'D:\soulseek\placebo - covers\01 Running up That Hill.mp3'.

If you have a particular requirement for a file list leave a comment on this post and I will look into it for you. Also, if anyone is interested in learning more about the various commands and programs available in the Command Prompt please leave a comment.

One last point, you can use > filename.txt to send the results of any command to a text file, which can be very useful if you have to pass information on to a technician.

Now you can impress your friends and co-workers with your 'old skool' techie skills.

20 comments:

Pseudorant said...

I remember having to do this back in the day (before Napster) to trade mp3's with people because transferring more than a couple songs on a 28.8 was a pain. Thanks for sparking that old memory!

jsanderz said...

Just to add:
If you want a full list of the commands available to you, just type "help" and they will be listed. You can then type "help command" for the instructions.
Regards.
Jsanderz

www.informationaddicts.com

Stepterix said...

p: I still use this command on occasion. Thanks for the comment

j: Thanks for the add; although, I would say that typing 'help command' wouldn't be much use.

Rather you need to type 'help ' followed by the command you wanted help on (like dir, or xcopy, etc). A pedantic point, I know, but on this blog I try to make things as clear as possible.

Cheers
K

Quakeboy said...

Really cool trick !
I knew > redirection... but never thought of using it this way..

أحمد said...

Thanks man ... I have been stuck in making an xml file wich list files for installaion, some thing related to joomlas installation pakage.

This simple command was a great help for me.

Keep up the good work

أحمد said...

I wonder if it is possible to make each file on a seperate line rather than all at the same line in the text file ?

installation*
lists*
which*

Stepterix said...

Thanks for the comments...

أحمد: Each file ends up on a different line when I do it, perhaps your text editor is not responding to the line feeds properly... if you use MS Word this article might be of interest to you

Drunken Dragon said...

What a nice tips. I'm looking the way for make a file and directory list on windows, but can't find it.

Pals20 said...

Thanks... I have hundreds of ebooks and this is a real simple and easy way of keeping track of my books. this was really, really helpful!

Stepterix said...

DD & P20: Glad to be of service.

Jean said...

I am trying in WORD to save a list of files which I have obtained by right clicking "Start" and choosing "Search". I click on "file" and it says "Save Search" and I click "yes" on this but the file that is saved is not readable.

Stepterix said...

Jean: I think that when you save a search like that, you save the details of the search rather than the results. In other words, it means that you can load the search criteria to look for those files again. I hope that this makes sense.

HerryDB said...

You are wonderfull!!! Thanks and thanks... Perfect.

Stepterix said...

HDB: Glad that the article was of use to you.

Anonymous said...

See www.f-fs.net/cs/xl07m33.html

Kevin Grieves said...

Anon: That would be very handy for anyone needing to process file information. Thanks

Murali's Blog - Share experience & Skills said...

Very useful to me. With the help of this I able to device my own commands and format for the output. Great!

Anonymous said...

Thank you soooo much!!!

I copied the line to a textpad page and saved it to the C:\windows directory as "list.bat"
now in vista all I need to do is SHFT right click on the folder choose "Open Command Window Here" and type "list" then enter and it's done!!!

Thank you again!!!!

Kevin Grieves said...

You are welcome. I am glad that these instructions still apply (I have not checked them in ages).

wil said...

i tweaked it so it will save the txt file to my desktop, i also added it to the folder (s) context menu