Created
March 8, 2013 17:18
-
-
Save steve-jansen/5118116 to your computer and use it in GitHub Desktop.
A Windows batch file designed to run at logon from the Start / Programs / Startup to do the following: SUBST drive letters, wipe the %TEMP% folder, and run the disk defragmenter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Name: Windows Startup.cmd | |
:: Purpose: A logon script to SUBST drive letters, wipe %TEMP%, and run defrag | |
:: Author: [email protected] | |
:: Revision: April 2012 | |
@ECHO OFF | |
SETLOCAL | |
:: map local folders to drive letters | |
CALL :MAPDRIVE P: "%USERPROFILE%\Documents\Visual Studio 2010\Projects" | |
REM CALL :MAPDRIVE U: "%USERPROFILE%" | |
:: wipe temp files | |
CALL :CLEARDIR "%SystemRoot%\Temp" | |
CALL :CLEARDIR "%TEMP%" | |
:launch the defrag tool | |
START "defrag" /LOW defrag.exe /C /U /V /X | |
@ECHO Done. | |
ENDLOCAL | |
EXIT /B 0 | |
:: FUNCTIONS | |
:MAPDRIVE | |
IF NOT EXIST "%~2" EXIT /B 1 | |
@ECHO Mapping %~1 to "%~2"... | |
IF EXIST "%~2" ( | |
IF NOT EXIST "%~1\" ( | |
SUBST "%~1" "%~2" | |
) | |
) | |
SUBST | FINDSTR /C:"%~1" 2>NUL | |
EXIT /B 0 | |
:CLEARDIR | |
IF NOT EXIST "%~1" EXIT /B 1 | |
@ECHO Deleting temporary files in "%~1"... | |
PUSHD "%~1"&&FOR /R %%I IN (.) DO CALL :CLEARFILES "%%~fI"&&POPD | |
EXIT /B 0 | |
:CLEARFILES | |
ECHO "%~1" | |
PUSHD "%~1"&&FOR %%I IN (*) DO @DEL /Q "%%~fI" >NUL 2>&1 | |
SET dir=%CD% | |
CD .. | |
RMDIR /S /Q "%dir%" >NUL 2>&1 | |
POPD | |
EXIT /B 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment