View unanswered posts | View active topics It is currently 02 Sep 2014 00:46



Post new topic Reply to topic  [ 6 posts ] 
get drive letters & drive types, if fixed drive, run dirms 
Author Message

Joined: 29 May 2008 14:03
Posts: 21
Location: Nauf Kakalak
Post get drive letters & drive types, if fixed drive, run dirms
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:

Code:
@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


07 Jun 2010 12:42
Profile
Expert

Joined: 22 Jan 2010 18:01
Posts: 1753
Location: Germany
Post Re: get drive letters & drive types, if fixed drive, run dir
I've no idea about dirms. But if it would work like
dirms C:\
you could try this
Code:
for /f "tokens=1,2*" %%a in (%log%) do (
  if "%%c"="Fixed Drive" (
    dirms %%a
  )
)


Regards
aGerman


07 Jun 2010 13:24
Profile

Joined: 29 May 2008 14:03
Posts: 21
Location: Nauf Kakalak
Post Re: get drive letters & drive types, if fixed drive, run dir
Thanks! We're getting closer. I'm having trouble getting that to work. Rehearsing some commands before committing to batch tells me that something about the for/if statement is amiss. Hint: fsutil... generates C:\ and dirms.exe only needs C. Also, the blank space before "Fixed Drive" may be getting in the way. I'll keep digging. Is there any way to do this without a text file at all? Can we wrap all of this up into one giant for loop?


07 Jun 2010 15:22
Profile
Expert

Joined: 22 Jan 2010 18:01
Posts: 1753
Location: Germany
Post Re: get drive letters & drive types, if fixed drive, run dir
Yeah, try this
Code:
@echo off

for /f "tokens=2" %%a in ('fsutil fsinfo drives') do (
  for /f "tokens=1* delims=:\- " %%b in ('fsutil fsinfo drivetype %%a') do (
    echo %%c|findstr /c:"Fixed Drive">nul && dirms %%b
  )
)



btw Sorry for my fault if "%%c"=="Fixed Drive" ... the second = was missing.

Regards
aGerman


07 Jun 2010 17:18
Profile

Joined: 29 May 2008 14:03
Posts: 21
Location: Nauf Kakalak
Post Re: get drive letters & drive types, if fixed drive, run dir
Looks great! I knew it would be simple like that. I'll try it out when I get to the office in the morning. Thanks!


07 Jun 2010 20:41
Profile

Joined: 29 May 2008 14:03
Posts: 21
Location: Nauf Kakalak
Post Re: get drive letters & drive types, if fixed drive, run dir
It works for the first fixed drive (C:) but doesn't make it to the second fixed drive (E:) on my workstation. I've also learned that while dirms.exe is fast and thorough, it doesn't always exit gracefully. I have replaced it with a call to XP-native file defrag.exe.

Thanks!


08 Jun 2010 13:26
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 


Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.