Useful tip to create a file list of .mp3s, disc images, or anything else in a folder

I’ve recently been looking into ways of organizing .mp3s and disc images of DVDs I have stored on an extra hard drive in my computer. I found a way to generate a text file that lists all files in any given folder. This is very easy to do and requires no additional software outside of Windows. I’ve tested it on XP. It should work on versions through 98.

  1. Open the folder containing the files you want to list (in Windows Explorer).

  2. Click start, Run, and type cmd. Click OK to open a DOS prompt.

  3. Type

cd /d "<directory>"

where is the information in the address bar for your Windows Explorer folder. Make sure you don’t forget the quotes around the directory name! You also don’t need the <>. They indicate a variable.

  1. This should bring you to the same DOS prompt, but instead of it saying C:\Documents and Settings\User> it should now say something like D:\Music MP3s>. From here, type
dir /b files.txt

That’s it! In the same folder where your music files are kept now, you should have a files.txt file that lists all the files in that folder in alphabetical order. Keep in mind, though, that this is a very simple filename parser built into Windows. It will only list files based on the filename. You can also build these commands into a batch file by creating a blank .txt file anywhere on your computer. Then type the following info into the .txt file:


cd /d "<directory>"
dir /b files.txt

Then rename the text file to something like Filenames.bat. You can call it whatever you want, just make sure you change the extension to .bat. To do this, you must make sure your “View extensions for known file types” is enabled in Folder Options. Then you can just run this .bat file anytime you want to update the list.

My two cents. I’m currently looking for a way to update an existing file with information from a separate dir listing, but I’ve found no way of doing this that doesn’t replace what’s already there. If anyone knows how to do this with a command line, please do tell.

Here’s an even easier way.

dir /a /-p /o:gen >filelisting.txt

Save it as filelisting.bat or whatever pleases you. Of course this requires the .bat file to be in the specific directory/folder to function.

And your “dir /b files.txt” should read “dir /b >files.txt” as the “>” is the redirect command.

And if you don’t know what the switches mean do a “DIR /?” and they will be explained.

As to merging or in reality appending the original file I don’t know of a switch for the redirect command that do that.

And lastly you don’t need to drop to dos to run the .bat file. Windows is smart enuff to know what is going on.

There is more than one way to skin a cat…

I know you don’t need to drop to DOS to run the .bat. I never said you had to. And yeah, I forgot the redirect >. My bad. I like my way better as it allows you to save the .bat on your desktop. Also, I think since this post is intended to direct the making of a filelist of music, etc. files, the /a and /-p switches are unnecessary, especially since you are printing to a file. I don’t know what use the /o:gen switch serves, unless you are using it alongside the /s switch to capture all subdirectories and their files. If you are simply running the command from a folder with your music or whatever files in it, you shouldn’t need to group subdirectories. I know there’s more than one way to skin a cat. Just sharing one that’s worked for me (and gave me quite a few headaches a couple years back).

Ok, how do you edit messages on this board? The option is missing from the original post…

Also, is it possible to use the /s switch but ONLY list subdirectories and their files? I want to capture 2 subdirectories of the same parent directory into the same text file, but I don’t want the other misc. files in the parent directory listed. Is this possible?

Once a message is posted there is a time frame of 30 minutes to edit it.

To append stuff to an existing txt you use double >

dir /b >> C:\list.txt

use that instead of a single > and it always appends to the ‘bottom’ of the list.

Also, is it possible to use the /s switch but ONLY list subdirectories and their files? I want to capture 2 subdirectories of the same parent director into the same text file, but I don’t want the other misc. files in the parent directory listed. Is this possible?

not possible, /s lists all files in all subdirs and such, to only get dirs and files in specific dirs you need to cd dir into them and then do either a /b or /s in that specific folder… :open_mouth:

I’ve made a batch file to archive the things on my DVDs that i burn, it’s two files, listed below… works great, however you need to read thru it and check the paths etc and customize to your needs :-p

First i run this batch file :

_launch_dvd_backup.bat

-START-

@ECHO OFF

ECHO.
ECHO.
ECHO      WELCOME TO THE DVD ARCHIVER V0.01
ECHO.
ECHO.
ECHO      PLEASE TYPE ARCH %%1 %%2
ECHO      WHERE %%1 REPRESENTS THE NAME OF THE DVD, 
ECHO      EXAMPLE: DVDX01X20031217
ECHO      AND %%2 REPRESENTS THE DVD NUMBER,
ECHO      EXAMLE: 001
ECHO.
ECHO      EXAMPLE: ARCH DVDX01X20031217 001
ECHO.
ECHO.
ECHO      TYPE EXIT TO EXIT.

F:

 vol

D:

cd\

ECHO.
ECHO.

PAUSE

cmd

-END-

and then from there i type ARCH, which runs this :

arch.bat

-START-

D:

md D:\STUFF_DATA_DVD_ARCHIVE_%2

F:

dir /b > D:\STUFF_DATA_DVD_ARCHIVE_%2%1_dirs.x

dir /s /b > D:\STUFF_DATA_DVD_ARCHIVE_%2%1_index.x

for /F %%x in (D:\STUFF_DATA_DVD_ARCHIVE_%2%1_dirs.x) do md “D:\STUFF_DATA_DVD_ARCHIVE_%2%%x”

for /F %%x in (D:\STUFF_DATA_DVD_ARCHIVE_%2%1_dirs.x) do md “D:\STUFF_OFFLINE_ARCHIVE_%%x%2”

cd\

dir /b > D:\STUFF_DATA_DVD_ARCHIVE_ emplist.x

D:

cls

ECHO.     PLEASE INSERT THE NEXT DISK AND PERSS ENTER

PAUSE

_launch_dvd_backup.bat

-END-

from this i get

DATA_DVD_ARCHIVE\001

with a dirlist (empty actual dirs), and two txt files, one containing the dir /b list, and the other a dir /s list for complete dir listing, both dirs and files…

eh crap it makes little sense but try it :-p

I know what you’re getting at here but I’ve developed a little batch script that will work for what I’m using it for. It looks like this:


del F:dummyfile.txt
cd /d E:
echo 	Index of E:\DVD Images - Movies >"DVDs on Drive.txt"
echo. >>"DVDs on Drive.txt"
dir "DVD Images\*.mdf" /b /a:-d >>"DVDs on Drive.txt"
echo. >>"DVDs on Drive.txt"
echo 	Index of E:\DVD Images\Series - Series >>"DVDs on Drive.txt"
echo. >>"DVDs on Drive.txt"
dir "DVD Images\Series\*.mdf" /b >>"DVDs on Drive.txt"
echo. >>"DVDs on Drive.txt"
echo 	Index of F:\DVD Images\ - Movies >>"DVDs on Drive.txt"
echo. >>"DVDs on Drive.txt"
cd /d F:\
dir "DVD Images\*.mdf" /b /a:-d >>"dummyfile.txt"
echo. >>"dummyfile.txt"
echo 	Index of F:\DVD Images\Series - Series >>"dummyfile.txt"
echo. >>"dummyfile.txt"
dir "DVD Images\Series\*.mdf" /b >>"dummyfile.txt"
cd /d E:\
type F:dummyfile.txt >>"DVDs on Drive.txt"
del F:dummyfile.txt

That gives me a nice little output that looks like this:


	Index of E:\DVD Images - Movies 
 
test.mdf
 
	Index of E:\DVD Images\Series - Series 
 
test.mdf
 
	Index of F:\DVD Images\ - Movies 
 
test.mdf
 
	Index of F:\DVD Images\Series - Series 
 
test.mdf

Of course, the test.mdf fields are actually populated by the files on my list. There are a lot there, though, so I condensed it. Works like a charm for me.

Now, when I finish with my copies I want to sort them so that like A-L are on drive E and M-Z are on drive F. I’ll have to do some researching to see if there’s a way to do this with a batch file. Who knows. Thanks for the help guys.

Well - I can only speak for 98, but

1st - Start | Run COMMAND (Cmd doesn’t work in 98, as it does in 2K/XP) - also that [cd /d] switch isn’t available for DIR in 9x (whatever that does for ya)…though the /b switch is nice for bare output, I notice when used in combo with the /s switch - it writes the full path

2nd. I have DOSKey loaded in Autoexec.bat at each startup for help in storing/cycling through previous commands (XP I think it’s on by default)

3rd I use [SET DIRCMD=/a /o:n] in Config.sys to always have all DOS output alphabetized

4th This likely won’t be helpful for your problem;

but;
by “hiding” (using hidden attribute) the other directories in the same parent and then using [dir /s > files.txt] will still give you all the parent’s files and dirs listings initially at the top - but only the “unhidden” subdirectory’s contents will be output - atleast in 98 anyway…obviously use [dir /s >> files.txt] to append to an existing file as noted by another here.

or - rather than getting jiggy with it…you could always just batch the 2 subs you want. Perhaps use CD to first change to subdirectory
[CD subdirectory1]
Dir /s >> …\files.txt
[CD subdirectory2
Dir /s >> …\files.txt

Dir /s >> …\files.txt -adds the changes to the files.txt file if it exists (or you want it to) in the parent dir of the one you’re in…because you’re located within the subdir already when running the DIR command and you want output the file one-level up (Parent)