'Is there a way to manually delete files/folders instead of running cleanmgr?

I am trying to write a batch file that can be run from PC to PC, that can clean the disk files in a deep clean fashion. Right now, I have every single checkmark selected in sageset, and I use that configuration using the /SAGERUN flag. Problem with this is that I cannot have it run silently, and I cannot specify what drive I want to clean. It just cleans them all. Furthermore, it has a glitch where if there are multiple drives, it freezes when switching to another disk, and will only unfreeze if the cursor hovers over the window. Is there a way to delete these files/folders from CMD or PS instead of using cleanmgr?

Below is the code wrapper I am using.

@echo off
color a

SET mypath=%~dp0

for /f "" %%i in ('PowerShell "hostname"') do (set SYSTEM_NAME=%%i)

IF NOT EXIST %mypath%\AutomatedLogs\%SYSTEM_NAME%\ (md %mypath%\AutomatedLogs)
IF NOT EXIST %mypath%\AutomatedLogs\%SYSTEM_NAME% (md %mypath%\AutomatedLogs\%SYSTEM_NAME%)

echo =====START AUTO LOG===== > %mypath:~0,-1%\AutomatedLogs\%SYSTEM_NAME%\%SYSTEM_NAME%_Automated_Log.txt
echo. >> %mypath:~0,-1%\AutomatedLogs\%SYSTEM_NAME%\%SYSTEM_NAME%_Automated_Log.txt

:cleanup
echo -----DISK CLEANUP----- >> %mypath:~0,-1%\AutomatedLogs\%SYSTEM_NAME%\%SYSTEM_NAME%_Automated_Log.txt
for /f "" %%i in ('PowerShell "Get-CimInstance -ClassName Win32_LogicalDisk | Where-Object DeviceID -eq 'C:' | Select-Object @{'Name' = 'FreeSpace (MB)'; Expression= { [int]($_.FreeSpace / 1MB) }} | Format-Table -HideTableHeaders"') do (set FREE_SPACE_BEFORE=%%i)
for /f "" %%i in ('PowerShell "Get-CimInstance -ClassName Win32_LogicalDisk | Where-Object DeviceID -eq 'C:' | Select-Object @{'Name' = 'TotalSpace (MB)'; Expression= { [int]($_.Size / 1MB) }} | Format-Table -HideTableHeaders"') do (set TOTAL_SPACE=%%i)

::RUN STUFFF TO CLEAN STUFFF
::reg import %mypath:~0,-1%\Cleaner.reg
net stop wuauserv
net stop wuauserv

::STUFF GOES HERE
reg import %mypath:~0,-1%\Cleaner.reg
START /W cleanmgr /sagerun:1 
::Currently what I am using ^^

powercfg -h off
powercfg -h on
net start wuauserv

for /f "" %%i in ('PowerShell "Get-CimInstance -ClassName Win32_LogicalDisk | Where-Object DeviceID -eq 'C:' | Select-Object @{'Name' = 'FreeSpace (MB)'; Expression= { [int]($_.FreeSpace / 1MB) }} | Format-Table -HideTableHeaders"') do (set FREE_SPACE_AFTER=%%i)
set /a "FREED_SPACE=%FREE_SPACE_AFTER%-%FREE_SPACE_BEFORE%"

for /f "" %%i in ('PowerShell "%FREED_SPACE%MB / 1GB"') do (set FREED_SPACE_NEW=%%i)
for /f "" %%i in ('PowerShell "%FREE_SPACE_BEFORE%MB / 1GB"') do (set FREE_SPACE_BEFORE_NEW=%%i)
for /f "" %%i in ('PowerShell "%TOTAL_SPACE%MB / 1GB"') do (set TOTAL_SPACE_NEW=%%i)
set FREED_SPACE_NEW=%FREED_SPACE_NEW:-=%
echo CLEANED SPACE: %FREED_SPACE_NEW% GB >> %mypath:~0,-1%\AutomatedLogs\%SYSTEM_NAME%\%SYSTEM_NAME%_Automated_Log.txt
echo FREE SPACE: %FREE_SPACE_BEFORE_NEW% GB >> %mypath:~0,-1%\AutomatedLogs\%SYSTEM_NAME%\%SYSTEM_NAME%_Automated_Log.txt
echo TOTAL SPACE: %TOTAL_SPACE_NEW% GB >> %mypath:~0,-1%\AutomatedLogs\%SYSTEM_NAME%\%SYSTEM_NAME%_Automated_Log.txt
echo =====EOF===== >> %mypath:~0,-1%\AutomatedLogs\%SYSTEM_NAME%\%SYSTEM_NAME%_Automated_Log.txt

::takeown /f "" /r /d y /A & icacls "" /grant WWCSSA:F /T & 

pause
cls
exit


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source