3

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.

4
  • Please if you vote down, comment the reasons to know how to improve my question. Thanks. Feb 10, 2012 at 15:14
  • 2
    My guess would be that someone downvoted because for me at least the very first item in a google search was essentially the answer. Hence "does not show any research effort"
    – EBGreen
    Feb 10, 2012 at 15:25
  • I really did not found anything useful :( Feb 10, 2012 at 15:48
  • 2
    Are you restricted to MS-DOS or can you use any version (FreeDOS, 4DOS etc)?
    – Shevek
    Feb 11, 2012 at 12:10

6 Answers 6

3

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.

1
  • @user3186092: the question is tagged as MS-DOS and the syntax is different from the windows scripts.
    – Hastur
    Mar 13, 2021 at 22:11
1

If you are only using DOS then here is a way to detect the type of drives attached:

http://www.dostips.com/DtCodeSnippets.php#Snippets.DrivesAndTypes

This doesn't work from Windows 7 Command Prompt so I have been unable to expand it further but it shouldn't be too difficult to add a loop to test for fixed disks and perform the dir.

0
1

You're very lucky. I still had my old DS.BTM script (a cut down and modernized version of a SYSINF.BAT that I picked up many years ago) on one machine, from which this is an excerpt. This requires JP Software's 4DOS, which is now freeware. As you can see, it picks up the LASTDISK value from DOS, and explicitly avoids removable and network drives.

@echo off
loadbtm on
do d = %@ascii[A] to %@ascii[%_lastdisk]

   iff %@ready[%@char[%d]:] EQ 1 then

       iff %@removable[%@char[%d]:] NE 1 .AND. %@remote[%@char[%d]:] NE 1 then

           dir /s /a: %@char[%d]:\

       endiff

   endiff

enddo

The people who have mistaken DOS for Windows in other answers will be pleased to know that this 4DOS script — taken from a twenty year old SYSINF.BAT script for 4DOS which I updated to newer versions of 4DOS and then ported to 4OS2 — still works, just the same as on 4DOS, with JP Software's TCC/LE on Windows NT 6.1.

3
  • just to say that the OP didn't explicitly exclude Windows to begin with, that was added as a later edit after some Windows answers were posted so there was no "mistaken DOS for Windows"
    – Shevek
    Feb 11, 2012 at 12:09
  • 1
    On the contrary: The questioner said DOS, twice, in the very first revision of the question.
    – JdeBP
    Feb 11, 2012 at 19:01
  • Thanks JdeBP and yes, i did not even talk about win, for me, after win 95, DOS in Windows is just "command line", like linux. DOS is DOS and always be :D Feb 12, 2012 at 1:35
0

so here is a command line method. Just use %% instead of % in a batch

for %d 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 (ifexist %d: (dir -a -h %d:\*.* /s > %d.txt))
8
  • but this also finds on some removable devices, not? For eg. a ZIP/CD/DVD/USB with that letters. Feb 10, 2012 at 15:49
  • there is any way to list only hdd, like linux? Feb 10, 2012 at 15:51
  • 1
    Well there are ways, but I've never tried in a batch. If I have time later I will try to work out a batch method.
    – EBGreen
    Feb 10, 2012 at 16:11
  • Hmmm...so I see that you have no windows access at all...I guess my question would be, why do you need to ignore for instance the floppy and CD drives?
    – EBGreen
    Feb 10, 2012 at 16:40
  • 1
    It checks if the drive exists. if there is no disk in a removable drive, it will fail with "not ready," and move on. I can envision this failing (stalling, retry prompt) with a read error, but this would not be unique to removable media.
    – horatio
    Feb 10, 2012 at 18:52
0

This can do the trick to check removable drivers without medias! http://www.ericphelps.com/batch/samples/adrive.bat.txt. It's a not documented function!

-1

My answer requires administrator rights. But in a BAT file run this:

echo list volume | diskpart

or if you want only the hard drives run this:

echo list volume | diskpart | Find /I "Partition"

In my script I needed a list of removable media so I could update all of my thumb drives at once. The nice thing about this is each drive is updated at the same time concurrently.

@echo off  
setlocal  

ECHO Searching for removable media. . .  

for /f "usebackq tokens=3 delims= " %%a in (`ECHO List Volume ^| DISKPART ^| FIND /I "Removable"`) do call :Launch %%a  

GOTO:EOF  

:Launch  
  set USB=%1:  
  ECHO Checking drive %USB%   
  IF NOT EXIST %USB%\MDT.bat ECHO Drive %USB% NOT MDT drive && GOTO:EOF  
  ECHO Found thumb drive starting Synch...  
  start %~dp1\Local_MDT_to_USB.bat %USB%  
GOTO:EOF  
1
  • I asked specifically for "MSDOS", not Windows Command Line Nov 1, 2013 at 20:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .