Batch file to cleanup OS temp and junk files.

Paul Black

I WANT TO BELIEVE!
Guru
Gold Member
VIP
Local time
3:30 AM
Messages
3,823
Location
Planet Earth VGhlIFgtRmlsZXM=
I am one who likes to keep my computers clean and running smoothly. All my files/folders etc are super organised and tidy [and yes, I do have OCD].

On a weekly basis I run ...

[1] Extended Disk Cleanup using a batch file.
[2] CCleaner [excluding the registry cleaner].
[3] Glary Utilities [excluding the registry cleaner].
[4] Clear ALL the Event Viewer logs using a batch file.

Note: Before anyone mentions the fact that these logs are useful if a problem arises for troubleshooting, I know that, and this is not the point of this post.

[5] Defragment.
[6] AVG.
[7] Malwarebytes.
[8] Backup my data etc.

Although the above does a great job, I wondered if creating a batch [.bat] file to remove ALL the temp and junk files that the above doesn't do would also be of an advantage!

I investigated this option and found many many scripts that claim that they do this with no detrimental downside or knock on affect at all. I tried some that stated this and they certainly didn't do what was stated and expected and they certainly did have a detrimental downside or knock on affect. In these cases I just restored my customised master system image [takes about 10 minutes].

Here is a script [I have just changed it slightly] that I ran on my Vista test computer that seems/appears to be quite good. I have attached the output given.

WARNING: Do NOT run the script below unless you understand batch script and know exactly what it will do. If you do run it, I advise you to make a System Image FIRST, just in case of problems or it has a detrimental downside or knock on affect!

Source => Computer Junk Files Cleaner – DIY Small Tool To Clean Junk Files In Computer.

Code:
@echo off
if not "%1" == "max" start /MAX cmd /c %0 max & exit/b
echo.
echo Cleaning system junk files, please wait . . .
echo.
del /f /s /q %systemdrive%\*.tmp
del /f /s /q %systemdrive%\*._mp
del /f /s /q %systemdrive%\*.log
del /f /s /q %systemdrive%\*.gid
del /f /s /q %systemdrive%\*.chk
del /f /s /q %systemdrive%\*.old
del /f /s /q %systemdrive%\recycled\*.*
del /f /s /q %windir%\*.bak
del /f /s /q %windir%\prefetch\*.*
rd /s /q %windir%\temp & md %windir%\temp
del /f /q %userprofile%\cookies\*.*
del /f /q %userprofile%\recent\*.*
del /f /s /q “%userprofile%\Local Settings\Temporary Internet Files\*.*”
del /f /s /q “%userprofile%\Local Settings\Temp\*.*”
del /f /s /q “%userprofile%\recent\*.*”
echo.
echo Junk files clean is finished!
echo. & pause

Results produced from the above run on my test system => View attachment Clean System Junk Files - RESULTS.txt.

I just wondered what you think about ...

[1] What it cleans.
[2] Whether or not it should clean what it does.
[3] Is there any detrimental downside or knock on affect.
[4] Are there any other items that can be safely included.

I have a few more items that could possibly be added which I may post at a later stage depending on the feedback received with regard to the above!

Thanks.
 
Last edited:

My Computer My Computer

At a glance

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux...Intel(R) Pentium(R) CPU P6200 @ 2.13GHz4.00 GBIntel(R) Graphics Media Accelerator HD
Computer type
Laptop
Computer Manufacturer/Model Number
Fujitsu LIFEBOOK
OS
Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
CPU
Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
Motherboard
FUJITSU FJNBB06
Memory
4.00 GB
Graphics Card(s)
Intel(R) Graphics Media Accelerator HD
Sound Card
[1] Realtek High Definition Audio [2] Intel(R) Display Audio
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
Hard Drives
TOSHIBA MK5076GSX
Antivirus
AVG FREE
Hi Paul,

you could use this fixlist via FRST

Start::
CreateRestorePoint:
CloseProcesses:

EmptyTemp:
End::



Roy
 

My Computer My Computer

At a glance

W7 home premium 32bit/W7HP 64bit/w10 tp insid...E5300 dual core3gbNvidia Geforce 7100 Nforce 630i
Computer type
PC/Desktop
Computer Manufacturer/Model Number
medionl/Aspire 6930G/acer x55a
OS
W7 home premium 32bit/W7HP 64bit/w10 tp insider ring
CPU
E5300 dual core
Motherboard
medion MS7366
Memory
3gb
Graphics Card(s)
Nvidia Geforce 7100 Nforce 630i
Monitor(s) Displays
avixc
Internet Speed
n (isp resticted to 72)
Antivirus
mse/pands
Browser
palemoon
Other Info
Belkin Fd7050 n USB using Railink RT2870 drivers, more upto date
Hi torchwood,

You could use this fixlist via FRST.

Thanks for the reply. However, FRST is mainly used for the diagnostics of malware and its ability to fix boot issues. The main idea of this thread is to produce a batch file that will clear all the temporary files and junk files [that other programs may not do] and has no detrimental downside or knock on affect to the running of the OS.
 

My Computer My Computer

At a glance

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux...Intel(R) Pentium(R) CPU P6200 @ 2.13GHz4.00 GBIntel(R) Graphics Media Accelerator HD
Computer type
Laptop
Computer Manufacturer/Model Number
Fujitsu LIFEBOOK
OS
Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
CPU
Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
Motherboard
FUJITSU FJNBB06
Memory
4.00 GB
Graphics Card(s)
Intel(R) Graphics Media Accelerator HD
Sound Card
[1] Realtek High Definition Audio [2] Intel(R) Display Audio
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
Hard Drives
TOSHIBA MK5076GSX
Antivirus
AVG FREE
Just use uncleaner it does it all and it's free https//m.majorgeeks.com/files/details/uncleaner.html
 

My Computer My Computer

At a glance

win 8 32 bit
Computer type
PC/Desktop
OS
win 8 32 bit
I keep my machines tidy too. In addition to cleaning, all personal shortcuts, folders and files have logical names and I have an easy-to-navigate filing system that I've maintained since Win 98.

I just removed FRST from my machine because I didn't remember downloading it and didn't know what it does.

How about the program TFC? Download TFC

How would I run your program? in the cmd window? I don't want to kill the CBS.log because I haven't been able to install security updates in over a year. How would I create an exception?
 

My Computer My Computer

At a glance

Win 7 Ult 64-bitG620 2.6GHZ Pentium R6 GB
Computer type
PC/Desktop
Computer Manufacturer/Model Number
HP p6-2020t
OS
Win 7 Ult 64-bit
CPU
G620 2.6GHZ Pentium R
Memory
6 GB
Monitor(s) Displays
25" HPLV2311
Screen Resolution
1920 x 1200
Hard Drives
1 SATA, 1 exterior SATA
Case
HP
Cooling
PSU
Antivirus
Glasswire
Browser
Waterfox; Firefox; Chrome for work
Other Info
Firewall--Glasswire
Similar specs in Gateway DX4200
Verizon FIOS Wired network

1 other Win7 computer-- has SSD
You are aware that Iobit is a Chinese company, right?
 

My Computer My Computer

At a glance

Win 7 Ult 64-bitG620 2.6GHZ Pentium R6 GB
Computer type
PC/Desktop
Computer Manufacturer/Model Number
HP p6-2020t
OS
Win 7 Ult 64-bit
CPU
G620 2.6GHZ Pentium R
Memory
6 GB
Monitor(s) Displays
25" HPLV2311
Screen Resolution
1920 x 1200
Hard Drives
1 SATA, 1 exterior SATA
Case
HP
Cooling
PSU
Antivirus
Glasswire
Browser
Waterfox; Firefox; Chrome for work
Other Info
Firewall--Glasswire
Similar specs in Gateway DX4200
Verizon FIOS Wired network

1 other Win7 computer-- has SSD
Hi RoWin7,

[1] How would I run your program? in the [2] cmd window? I don't want to kill the CBS.log because I haven't been able to install security updates in over a year. [3] How would I create an exception?

[1] It isn't my program. It is from the source that I posted.
[2] Yes, from an elevated command prompt.
[3] You could probably rename the suffix to something else that isn't currently included in the cleaning criteria, something like .zzz for example, and then revert it back to .log after you have run the program.

As I said, this is not my program, so if you are going to run it I would backup your OS first.
The program performs more of a generalised clean, rather than a specific clean.
A program can be written to only clean specific items of temp and junk files. I might decide to do something like that one day, but for now, I am just intereted in seeing if the generalised clean has any detrimental downside or knock on affect, and possibly if other items can be added/removed from it!

You are aware that Iobit is a Chinese company, right?

Yes I do! I have used IOBIT Smart Defrag etc in the past without any issues.
 

My Computer My Computer

At a glance

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux...Intel(R) Pentium(R) CPU P6200 @ 2.13GHz4.00 GBIntel(R) Graphics Media Accelerator HD
Computer type
Laptop
Computer Manufacturer/Model Number
Fujitsu LIFEBOOK
OS
Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
CPU
Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
Motherboard
FUJITSU FJNBB06
Memory
4.00 GB
Graphics Card(s)
Intel(R) Graphics Media Accelerator HD
Sound Card
[1] Realtek High Definition Audio [2] Intel(R) Display Audio
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
Hard Drives
TOSHIBA MK5076GSX
Antivirus
AVG FREE
Hi

I've used TFC, (really old prog) for years, and 1 click event cleaner, Brinks TUT.
As for Iobit thier defrag/uninstaller are really good, they got creamed because of the MWB AV debacle, they now use Bitdefender UNDER LICIENCE.
(ps it was started by a couple of Americans, moved to China coz it was less regulated)

As for FRST well granted its primarilly antimalware tool, just using the FIX option turns it into a Batch script prog

Roy
RoWin7 post the CBS i'll look it over, are normal updates installing??
 

My Computer My Computer

At a glance

W7 home premium 32bit/W7HP 64bit/w10 tp insid...E5300 dual core3gbNvidia Geforce 7100 Nforce 630i
Computer type
PC/Desktop
Computer Manufacturer/Model Number
medionl/Aspire 6930G/acer x55a
OS
W7 home premium 32bit/W7HP 64bit/w10 tp insider ring
CPU
E5300 dual core
Motherboard
medion MS7366
Memory
3gb
Graphics Card(s)
Nvidia Geforce 7100 Nforce 630i
Monitor(s) Displays
avixc
Internet Speed
n (isp resticted to 72)
Antivirus
mse/pands
Browser
palemoon
Other Info
Belkin Fd7050 n USB using Railink RT2870 drivers, more upto date
Hi torchwood,

I've used TFC, (really old prog) for years, and 1 click event cleaner, Brinks TUT.

I will have a closer look at TFC [Temp File Cleaner]. It would be nice if I can get to see the script if it is open source.

As for Iobit thier defrag/uninstaller are really good, they got creamed because of the MWB AV debacle, they now use Bitdefender UNDER LICIENCE.
(ps it was started by a couple of Americans, moved to China coz it was less regulated)

For uninstalling I use Revo Uninstaller because you can run the Advanced Scan option to scan for leftover items which is excellent!

As for FRST well granted its primarilly antimalware tool, just using the FIX option turns it into a Batch script program.

Again, I will have a closer look at FRST [Farbar Recovery Scan Tool]. It would be nice if I can get to see the script if it is open source.
 

My Computer My Computer

At a glance

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux...Intel(R) Pentium(R) CPU P6200 @ 2.13GHz4.00 GBIntel(R) Graphics Media Accelerator HD
Computer type
Laptop
Computer Manufacturer/Model Number
Fujitsu LIFEBOOK
OS
Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
CPU
Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
Motherboard
FUJITSU FJNBB06
Memory
4.00 GB
Graphics Card(s)
Intel(R) Graphics Media Accelerator HD
Sound Card
[1] Realtek High Definition Audio [2] Intel(R) Display Audio
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
Hard Drives
TOSHIBA MK5076GSX
Antivirus
AVG FREE
Hi torchwood,

@RoWin7 post the CBS i'll look it over, are normal updates installing?

Would you be interested in or find this useful!

I know that you are one of the few members here that can analise and diagnose the CBS.log. I have written a batch program that will extract the errors ONLY from the CBS.log. SFC [System File Checker] MUST obviously be run BEFORE running the batch program. The batch program creates a sfc_details.txt file on the desktop. Would it help you to analise and diagnose problems of the CBS.log that members are asked to upload here at SevenForums because it will only contain the exracted errors?
 

My Computer My Computer

At a glance

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux...Intel(R) Pentium(R) CPU P6200 @ 2.13GHz4.00 GBIntel(R) Graphics Media Accelerator HD
Computer type
Laptop
Computer Manufacturer/Model Number
Fujitsu LIFEBOOK
OS
Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
CPU
Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
Motherboard
FUJITSU FJNBB06
Memory
4.00 GB
Graphics Card(s)
Intel(R) Graphics Media Accelerator HD
Sound Card
[1] Realtek High Definition Audio [2] Intel(R) Display Audio
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
Hard Drives
TOSHIBA MK5076GSX
Antivirus
AVG FREE
error
 

My Computer My Computer

At a glance

Win 7 Ult 64-bitG620 2.6GHZ Pentium R6 GB
Computer type
PC/Desktop
Computer Manufacturer/Model Number
HP p6-2020t
OS
Win 7 Ult 64-bit
CPU
G620 2.6GHZ Pentium R
Memory
6 GB
Monitor(s) Displays
25" HPLV2311
Screen Resolution
1920 x 1200
Hard Drives
1 SATA, 1 exterior SATA
Case
HP
Cooling
PSU
Antivirus
Glasswire
Browser
Waterfox; Firefox; Chrome for work
Other Info
Firewall--Glasswire
Similar specs in Gateway DX4200
Verizon FIOS Wired network

1 other Win7 computer-- has SSD

My Computer My Computer

At a glance

Win 7 Ult 64-bitG620 2.6GHZ Pentium R6 GB
Computer type
PC/Desktop
Computer Manufacturer/Model Number
HP p6-2020t
OS
Win 7 Ult 64-bit
CPU
G620 2.6GHZ Pentium R
Memory
6 GB
Monitor(s) Displays
25" HPLV2311
Screen Resolution
1920 x 1200
Hard Drives
1 SATA, 1 exterior SATA
Case
HP
Cooling
PSU
Antivirus
Glasswire
Browser
Waterfox; Firefox; Chrome for work
Other Info
Firewall--Glasswire
Similar specs in Gateway DX4200
Verizon FIOS Wired network

1 other Win7 computer-- has SSD

My Computer My Computer

At a glance

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux...Intel(R) Pentium(R) CPU P6200 @ 2.13GHz4.00 GBIntel(R) Graphics Media Accelerator HD
Computer type
Laptop
Computer Manufacturer/Model Number
Fujitsu LIFEBOOK
OS
Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
CPU
Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
Motherboard
FUJITSU FJNBB06
Memory
4.00 GB
Graphics Card(s)
Intel(R) Graphics Media Accelerator HD
Sound Card
[1] Realtek High Definition Audio [2] Intel(R) Display Audio
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
Hard Drives
TOSHIBA MK5076GSX
Antivirus
AVG FREE
What doesn't the Windows Disk Cleanup utility do in this regard?
 

My Computer My Computer

At a glance

Windows 7 Pro SP1 64 bit8 GB
Computer type
Laptop
Computer Manufacturer/Model Number
Dell M6500 Precision Work Station
OS
Windows 7 Pro SP1 64 bit
Memory
8 GB
Screen Resolution
1920x
Internet Speed
30 Mbps
Antivirus
Norton Security
Browser
IE 11
Hi torchwood,

Hi torchwood,

Would you be interested in or find this useful!

I know that you are one of the few members here that can analise and diagnose the CBS.log. I have written a batch program that will extract the errors ONLY from the CBS.log. SFC [System File Checker] MUST obviously be run BEFORE running the batch program. The batch program creates a sfc_details.txt file on the desktop. Would it help you to analise and diagnose problems of the CBS.log that members are asked to upload here at SevenForums because it will only contain the exracted errors?
 

My Computer My Computer

At a glance

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux...Intel(R) Pentium(R) CPU P6200 @ 2.13GHz4.00 GBIntel(R) Graphics Media Accelerator HD
Computer type
Laptop
Computer Manufacturer/Model Number
Fujitsu LIFEBOOK
OS
Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
CPU
Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
Motherboard
FUJITSU FJNBB06
Memory
4.00 GB
Graphics Card(s)
Intel(R) Graphics Media Accelerator HD
Sound Card
[1] Realtek High Definition Audio [2] Intel(R) Display Audio
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
Hard Drives
TOSHIBA MK5076GSX
Antivirus
AVG FREE
Paul--

Something's zonky at the forum. I've received notices of post #15 in my email 3 times. Maybe Torchwood's reply is floating in the ethernet.

Tried your script now.
It shut down my Elev Command window, of course didn't run
 

My Computer My Computer

At a glance

Win 7 Ult 64-bitG620 2.6GHZ Pentium R6 GB
Computer type
PC/Desktop
Computer Manufacturer/Model Number
HP p6-2020t
OS
Win 7 Ult 64-bit
CPU
G620 2.6GHZ Pentium R
Memory
6 GB
Monitor(s) Displays
25" HPLV2311
Screen Resolution
1920 x 1200
Hard Drives
1 SATA, 1 exterior SATA
Case
HP
Cooling
PSU
Antivirus
Glasswire
Browser
Waterfox; Firefox; Chrome for work
Other Info
Firewall--Glasswire
Similar specs in Gateway DX4200
Verizon FIOS Wired network

1 other Win7 computer-- has SSD
Hi RoWin7,

[1] Something's zonky at the forum. I've received notices of post #15 in my email 3 times. Maybe Torchwood's reply is floating in the ethernet.

[2] Tried your script now.
It shut down my Elev Command window, of course didn't run

[1] Yes. I had a couple of problems yesterday where I lost a couple of posts, one of them being post #15, hence you receiving a reply notification that didn't exist so I had ro re-post it. The forum changed over to a new server yesterday which probably caused this minimal clitch.

EDIT: Just seen this post by Barman58 => We moved our server holding this Forum Yesterday.

[2] It is NOT my script but one that can be found in the source link I provided.

I hope this helps!
 

My Computer My Computer

At a glance

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux...Intel(R) Pentium(R) CPU P6200 @ 2.13GHz4.00 GBIntel(R) Graphics Media Accelerator HD
Computer type
Laptop
Computer Manufacturer/Model Number
Fujitsu LIFEBOOK
OS
Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
CPU
Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
Motherboard
FUJITSU FJNBB06
Memory
4.00 GB
Graphics Card(s)
Intel(R) Graphics Media Accelerator HD
Sound Card
[1] Realtek High Definition Audio [2] Intel(R) Display Audio
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
Hard Drives
TOSHIBA MK5076GSX
Antivirus
AVG FREE
Hi RoWin7,

Out of interest!

[1] Did you copy the script in post #1 into notepad and save it as a Filename: with a .bat suffix and Save as type: All Files?
[2] Did you include the echo. & pause at the very end of the code?
[3] Did you run it from an elevated command prompt?
[4] Did you see the IMPORTANT section?

I would assume that you didn't run it from an elevated command prompt!
 
Last edited:

My Computer My Computer

At a glance

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux...Intel(R) Pentium(R) CPU P6200 @ 2.13GHz4.00 GBIntel(R) Graphics Media Accelerator HD
Computer type
Laptop
Computer Manufacturer/Model Number
Fujitsu LIFEBOOK
OS
Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
CPU
Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
Motherboard
FUJITSU FJNBB06
Memory
4.00 GB
Graphics Card(s)
Intel(R) Graphics Media Accelerator HD
Sound Card
[1] Realtek High Definition Audio [2] Intel(R) Display Audio
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
Hard Drives
TOSHIBA MK5076GSX
Antivirus
AVG FREE
1--No, I just copied it into my clipboard program and pasted it into the window. If I had saved it as a file, I wouldn't have known how to do it on Elevated Command prompt.
2--I copied and pasted exactly what you wrote.
3-- yes

Not going to play with it anymore.

Are you thinking of sending your variation to Brink as a tutorial?
 

My Computer My Computer

At a glance

Win 7 Ult 64-bitG620 2.6GHZ Pentium R6 GB
Computer type
PC/Desktop
Computer Manufacturer/Model Number
HP p6-2020t
OS
Win 7 Ult 64-bit
CPU
G620 2.6GHZ Pentium R
Memory
6 GB
Monitor(s) Displays
25" HPLV2311
Screen Resolution
1920 x 1200
Hard Drives
1 SATA, 1 exterior SATA
Case
HP
Cooling
PSU
Antivirus
Glasswire
Browser
Waterfox; Firefox; Chrome for work
Other Info
Firewall--Glasswire
Similar specs in Gateway DX4200
Verizon FIOS Wired network

1 other Win7 computer-- has SSD
Hi RoWin7,

1--No, I just copied it into my clipboard program and pasted it into the window.
That's why it didn't work!
It has to be run from a .bat file as an Administrator.

Are you thinking of sending your variation to Brink as a tutorial?
That's NOT my variation. My variation will be a bit more complex!
I am just putting something together for me really, hence my request for what others thought!

I hope this helps!
 

My Computer My Computer

At a glance

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux...Intel(R) Pentium(R) CPU P6200 @ 2.13GHz4.00 GBIntel(R) Graphics Media Accelerator HD
Computer type
Laptop
Computer Manufacturer/Model Number
Fujitsu LIFEBOOK
OS
Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
CPU
Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
Motherboard
FUJITSU FJNBB06
Memory
4.00 GB
Graphics Card(s)
Intel(R) Graphics Media Accelerator HD
Sound Card
[1] Realtek High Definition Audio [2] Intel(R) Display Audio
Screen Resolution
1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
Hard Drives
TOSHIBA MK5076GSX
Antivirus
AVG FREE
Back
Top