get drive letters & drive types, if fixed drive, run dirms
Posted: 07 Jun 2010 12:42
I'm working on a batch that can get the drive letters and drive types via fsutil fsinfo ... but I'm stuck with the if logic that follows. If the drive type is fixed, I'd like to run a defrag utility called dirms.exe. Once this is solved, I'd have one batch file that can run as a scheduled task on every machine, regardless of drive configurations. Right now I'm redirecting to a text file, as I'm not sure what to do next.
So far I can get the drive letters and drive type:
The text file %log% contains the following:
C:\ - Fixed Drive
D:\ - CD-ROM Drive
M:\ - Remote/Network Drive
How do I run dirms.exe only on the fixed drive? I've read a bit about IF and ELSE, but I'm quite confused. Can someone nudge me in the right direction?
Thanks,
Dave
So far I can get the drive letters and drive type:
Code: Select all
@echo off
title DefragDotBat
rem set log file name and location
set log=c:\util\DefragDotBat.log
rem get drive letters
set "drlist="
for /f "tokens=*" %%a in ('fsutil fsinfo drives^|find /v ""') do (
set "dr=%%a"
call set drlist=%%drlist%% %%dr:~-3%%
)
rem use drive letters to get drive type
for %%a in (%drlist%) do fsutil fsinfo drivetype %%a >> %log%
rem now defrag fixed drives and exclude optical and remote/network drives
The text file %log% contains the following:
C:\ - Fixed Drive
D:\ - CD-ROM Drive
M:\ - Remote/Network Drive
How do I run dirms.exe only on the fixed drive? I've read a bit about IF and ELSE, but I'm quite confused. Can someone nudge me in the right direction?
Thanks,
Dave