How to list all files on all hard drives with output in MS-DOS batch

batchms-dos

How can I list all files (including system and hidden) on all hard drives (not removable drives)?

I think in something like a:

dir -a -h *.* /s > file.txt

but this is for the specific drive where I'm.

How can I do something like that but with C:, D:, etc,
but I don't know the DOS's name of the drivers, and i need a .bat to do this (an automatic listing). Implementer can't also know the names of drivers.

Best Answer

There is a program that can detect CD drives (FINDCD.EXE) that comes on some boot disks (including the Windows 98 Emergency Boot Disk) which you can use in a batch file to skip them:

@echo off
findcd.exe
if (%1)==() goto start

:dirit
if not exist %1:\*.* goto done
if (%1)==(%CDROM%) goto done
dir /a/s/o %1:\*.* >> c:\Files.txt
goto done

:start
for %i in (c d e f g h i j k l m n o p q r s t u v w x y z) do call %0 %i
goto done

:done

I just threw this together off the top of my head (with no testing since I am currently in Windows), but it should do the trick for the most part. Note that floppy drives are always assigned a drive letter starting with A while hard-drives always start at C, so this skips A and B.

There is also a program that can detect RAM drives (FINDRAMD.EXE) which you can use to detect and skip RAM drives if you have those, but that requires more work (and a separate batch file). Look at SETRAMD.BAT which is usually included for an example.

Related Question