How to Clean the C Drive of a Windows Cloud Server

05-01-2024 02:31:41

After running for a period of time, the C drive in a Windows system tends to diminish in size. The temporary folder in the C drive plays a role in interacting data with programs. If the C drive becomes full, many programs will fail to operate. The following will demonstrate how to clean up the C drive's junk in bulk by writing a batch file.

Cleaning the drive C carries some risks. Please carefully read the following batch file and code description, ensuring there are no important files you need, before proceeding with the operation. Simply save the following content as a .bat file on the server's desktop, then double-click to run it.

@echo off
echo During the process of clearing system junk, please wait...
del /f /s /q %systemdrive%\*.tmp
del /f /s /q %systemdrive%\*.log
del /f /s /q %systemdrive%\recycled\*.*
del /f /s /q %windir%\*.bak
del /f /s /q %windir%\Prefetch\*.*
del /f /s /q %windir%\ServicePackFiles\*.*
rd /s /q %windir%\temp & md %windir%\temp
echo System junk cleared! Press any key to continue...
pause

Code Explanation:

del /f /s /q is the delete command. The three parameters following it mean: force delete, include subdirectories, and quiet mode (no confirmation required).
%systemdrive% represents the C drive. Since the /s parameter is already set, there's no need to write a specific directory afterwards, and it will delete all tmp/log files under the C drive.

%windir% represents the Windows installation directory, such as C:\Windows.
The rd md line of code is used to delete the entire C:\Windows\Temp directory and then recreate it."