DosTips.com

A Forum all about DOS Batch
It is currently 28 May 2016 18:03

All times are UTC-06:00




Post new topic  Reply to topic  [ 6 posts ] 
Author Message
PostPosted: 07 Jun 2010 12:42 
Offline

Joined: 29 May 2008 14:03
Posts: 24
Location: Nauf Kakalak
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


Top
   
PostPosted: 07 Jun 2010 13:24 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 1987
Location: Germany
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


Top
   
PostPosted: 07 Jun 2010 15:22 
Offline

Joined: 29 May 2008 14:03
Posts: 24
Location: Nauf Kakalak
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?


Top
   
PostPosted: 07 Jun 2010 17:18 
Offline
Expert

Joined: 22 Jan 2010 18:01
Posts: 1987
Location: Germany
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


Top
   
PostPosted: 07 Jun 2010 20:41 
Offline

Joined: 29 May 2008 14:03
Posts: 24
Location: Nauf Kakalak
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!


Top
   
PostPosted: 08 Jun 2010 13:26 
Offline

Joined: 29 May 2008 14:03
Posts: 24
Location: Nauf Kakalak
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!


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: misol101, Yahoo [Bot] and 4 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® Forum Software © phpBB Limited