tonysathre Posted April 26, 2007 Share Posted April 26, 2007 I was bored so I wrote this defrag script that will defrag all the volumes on your system. Enjoy! @echo off ::==defragger.bat set logfile=c:defrag.log set oldfiles=drives drives.log drives.txt new.txt newlist.txt final.txt for %%i in (%oldfiles%) do if exist %%i ( del /q /f %%i > nul ) if "%logfile%" == "" ( goto :no_log ) else ( goto :log ) :log echo Defragger started at %time% on %date% by %username% on workstation %computername% > "%logfile%" echo. >> "%logfile%" echo. >> "%logfile%" for /f "tokens=1 delims=:" %%i in ('reg query hklmsystemmounteddevices ^| findstr DosDevices') do ( echo %%i >> drives ) for /f "tokens=3 delims=" %%i in (drives) do ( echo %%i >> drives.txt ) for /f %%i in (drives.txt) do ( echo %%i: >> drives.log ) sort drives.log >> new.txt type new.txt | findstr "A" > nul if errorlevel 0 for /f "tokens=1 skip=1" %%i in (new.txt) do echo %%i >> newlist.txt for /f %%i in (newlist.txt) do fsutil fsinfo drivetype %%i | findstr "Fixed" >> final.txt for %%i in (drives drives.log drives.txt new.txt newlist.txt final.txt) do attrib +h %%i for /f %%i in (final.txt) do ( defrag -a %%i | findstr "should" > nul if errorlevel 0 title Defragging %%i && echo Defragging %%i && defrag %%i >> "%logfile%" echo. echo. echo Defrag on drive %%i completed at %time% ) echo Defragger completed at %time% >> "%logfile%" echo Defragger completed successfully del /q /f drives > nul del /q /f drives.txt > nul del /q /f drives.log > nul del /q /f new.txt > nul del /q /f newlist.txt > nul del /q /f final.txt > nul echo. echo Log file saved to %logfile% echo Would you like to view the log file now? [y/n] set /p choice=%1 if "%choice" == "y" notepad "%logfile%" if "%choice%" == "yes" notepad "%logfile%" pause goto :eof :no_log for /f "tokens=1 delims=:" %%i in ('reg query hklmsystemmounteddevices ^| findstr DosDevices') do ( echo %%i >> drives ) for /f "tokens=3 delims=" %%i in (drives) do ( echo %%i >> drives.txt ) for /f %%i in (drives.txt) do ( echo %%i: >> drives.log ) sort drives.log >> new.txt type new.txt | findstr "A" > nul if errorlevel 0 for /f "tokens=1 skip=1" %%i in (new.txt) do echo %%i >> newlist.txt for /f %%i in (newlist.txt) do fsutil fsinfo drivetype %%i | findstr "Fixed" >> final.txt for %%i in (drives drives.log drives.txt new.txt newlist.txt final.txt) do attrib +h %%i for /f %%i in (final.txt) do ( defrag -a %%i | findstr "should" > nul if errorlevel 0 title Defragging %%i && defrag -f %%i echo. echo. echo Defrag on drive %%i completed at %time% ) echo Defragger completed successfully del /q /f drives > nul del /q /f drives.txt > nul del /q /f drives.log > nul del /q /f new.txt > nul del /q /f newlist.txt > nul echo Press any key to close this window pause > nul goto :eof ::--------------[ EOF ]--------------:: Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.