Batch file to create a folder in every removable device
Solution 1:
Why is this not working?
'wmic volume get driveLetter^ where drivertype=2
You have several errors in the above wmic
command:
-
drivertype
should bedrivetype
. - There is a missing trailing
'
. - The `^ is not needed.
- The
where
should come before theget
. - Not all disk volumes have drive letters (but logical disks do).
Use the following batch file:
@echo off
setlocal
for /f "skip=1 tokens=1,2" %%d in ('wmic logicaldisk get caption^, drivetype') do (
if [%%e]==[2] echo mkdir %%d\test
)
endlocal
Notes:
- Remove the
echo
beforemkdir
when you have tested the batch file. - You may need to do something with drive type 3 as well.
-
I have a removable drive of type 3. In the below output C: is a fixed hard disk, D: is my CD ROM drive, E: is a removable USB stick and F: is a removable external USB drive.
F:\test>wmic logicaldisk get deviceid, drivetype DeviceID DriveType C: 3 D: 5 E: 2 F: 3
Further Reading
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- for /f - Loop command against the results of another command.
- wmic - Windows Management Instrumentation Command.