Page 1 of 1

Batch file to keep computer clean

Posted: 11 Feb 2011 17:52
by kenlou
I am setting up a computer for my nephew , have had it now for a while,and am wanting to create a batch file that he can run once a week from his desktop to help keep his computer halfway clean. Here is what I would like to do:

On the C:\drive I would like to have these deleted:

all .tmp files
all ._mp files
all .log files
all .gid files
all .chk files
all .old files
all .bak files
all files in Windows\Temp folder
all files in Local Settings\Temp folder

I also have a hidden drive K: that I have moved my Temp folder to and have also moved the Temporary Internet File folder there, so I would also like to have the following deleted from the K: drive

all files and folders in K:\Temp
all files and folders in K:\Temp\Low
all files in K:\Temp\Temporary Internet Files folder

and I also would like to add the following to the end of this batch file:(This runs perfectdisk to defrag his drives)


@ECHO OFF
::Determine the path to the PerfectDisk program
Set Reg.Key=HKLM\Software\Microsoft\Windows\CurrentVersion\AppPaths\PerfectDisk.exe
Set Reg.Val=Path
For /F "Tokens=2*" %%A In ('Reg Query "%Reg.Key%" /v "%Reg.Val%" ^|

Find /I "%Reg.Val%"') Do Call Set PathDirectory=%%B
Set PerfectDiskPath=%PathDirectory%
::Perform a Smart Placement defrag on drive C:. Wait until complete

before returning control.
"%PerfectDiskPath%pdcmd" /AllDrives /SP /WAIT
::Shutdown Windows Force running aplications to close and wait for 10

seconds and then shutdown Windows
shutdown.exe -s -f -t 10


running Vista Ultimate 64 with 8 gigs ram, gtx 260 Graphics card, core 2 duo e8500

Any help to get this thing back to him would be appreciated

Re: Batch file to keep computer clean

Posted: 12 Feb 2011 08:02
by aGerman
First you should have a look at DEL.
/S and /Q seem to be interresting :wink:

Code: Select all

pushd C:\
del /s /q *.tmp
:: the same for all other file types
:: ...
popd

del /s /q "K:\Temp\*.*"
:: etc.
:: ...


Regards
aGerman

Re: Batch file to keep computer clean

Posted: 12 Feb 2011 18:41
by kenlou
Thanks for the quick reply.
I know very little about batch files, do you see anything wrong with this?

@echo off
cls

pushd C:\
del /f /s /q *.tmp
del /f /s /q *._mp
del /f /s /q *.log
del /f /s /q *.gid
del /f /s /q *.chk
del /f /s /q *.old
del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\*.*"
del /f /s /q "%userprofile%\Local Settings\Temp\*.*"
del /f /s /q %windir%\*.bak
rd /s /q "%userprofile%\Local Settings\Temp\" & md "%userprofile%\Local

Settings\Temp\"
rd /s /q %windir%\Temp & md %windir%\Temp

popd

del /f /s /q "K:\Temp\Low\*.*"
del /f /s /q "K:\Temp\Temporary Internet Files\*.*"
del /f /s /q "K:\Temp\*.*"
rd /s /q K:\Temp\Low
rd /s /q K:\Temp\Temporary Internet Files
rd /s /q K:\Temp
md K:\Temp
md K:\Temp\Low
md K:\Temp\Temporary Internet Files
/WAIT
cls

@ECHO OFF
::Determine the path to the PerfectDisk program
Set Reg.Key=HKLM\Software\Microsoft\Windows\CurrentVersion\App

Paths\PerfectDisk.exe
Set Reg.Val=Path
For /F "Tokens=2*" %%A In ('Reg Query "%Reg.Key%" /v "%Reg.Val%" ^| Find /I "%

Reg.Val%"') Do Call Set PathDirectory=%%B
Set PerfectDiskPath=%PathDirectory%
::Perform a Smart Placement defrag on drive C:. Wait until complete before

returning control.
"%PerfectDiskPath%pdcmd" /AllDrives /SP /WAIT
::Shutdown Windows Force running aplications to close and wait for 10 seconds

and then shutdown Windows
shutdown.exe -s -f -t 10

Re: Batch file to keep computer clean

Posted: 12 Feb 2011 19:16
by aGerman
Well, it's your own risk to delete all these files on the entire drive. I would delete files and folders only in the %temp% directory.
I'm not sure if you're able to delete the temporary internet files. As far as I remember these files are not a part of the file system, they are displayed virtually. You have to figure out whether it would work.
I have no idea of PerfectDisk, though it looks right.

Regards
aGerman