DOS Batch script to iterate through NTFS drives

Posted on

QUESTION :

I need a Batch FOR loop that iterates through the driveletters of NTFS drives only.

I found a way to do a FOR loop like so:

for %%X in (C: D: E: F: G:) do <bla>

Obviously I could go A-Z to get all drives, however, how can I enforce that it only goes through NTFS drives and not FAT32, CDFS, etc.?

Can I build in a check somehow or generate the array of driveletters beforehand?

Yes, it has to be Windows Batch DOS, so no powershell, vbscript or other languages please.

ANSWER :

for /f %%A in ('wmic logicaldisk where "FileSystem='NTFS'" get name') do ...

Note that the values in %%A will not include the backslash. They will look like C:, D:, etc.

Leave a Reply

Your email address will not be published.