The Notebook Review forums were hosted by TechTarget, who shut down them down on January 31, 2022. This static read-only archive was pulled by NBR forum users between January 20 and January 31, 2022, in an effort to make sure that the valuable technical information that had been posted on the forums is preserved. For current discussions, many NBR forum users moved over to NotebookTalk.net after the shutdown.
Problems? See this thread at archive.org.

    Help me make a batch file to clean temp files

    Discussion in 'Windows OS and Software' started by Spartan@HIDevolution, Oct 28, 2014.

  1. Spartan@HIDevolution

    Spartan@HIDevolution Company Representative

    Reputations:
    39,567
    Messages:
    23,559
    Likes Received:
    36,826
    Trophy Points:
    931
    Can someone tell me what text I need to type to create a batch file that would delete the following folders because I have fixed all my event log errors so far with the exception of the indexing error:



    Upon doing some search, I found that CCleaner may be behind this so I wanna try a format without ever using CCleaner

    PS: Re-building the Index doesn't help

    What I want the batch file to delete is the following:

    1) C:\Windows\Temp (delete all the files and folders in that folder but not the folder itself)

    2) C:\Users\MYUSERNAME\AppData\Local\Temp (delete all the files and folders in that folder but not the folder itself)

    3) C:\Windows\SoftwareDistribution\Download (delete all the files and folders in that folder but not the folder itself)

    Thanks
     
  2. Spartan@HIDevolution

    Spartan@HIDevolution Company Representative

    Reputations:
    39,567
    Messages:
    23,559
    Likes Received:
    36,826
    Trophy Points:
    931
    can you please do it for me with that force to delete hidden files as well, I'm a noobie man :(
     
  3. Spartan@HIDevolution

    Spartan@HIDevolution Company Representative

    Reputations:
    39,567
    Messages:
    23,559
    Likes Received:
    36,826
    Trophy Points:
    931
    just tried it and ran it as admin bro, not deleting any files from Software Distribution nor the appdata\local\temp files not the Temp folder :( :(
     
  4. Spartan@HIDevolution

    Spartan@HIDevolution Company Representative

    Reputations:
    39,567
    Messages:
    23,559
    Likes Received:
    36,826
    Trophy Points:
    931
    I copy/pasted what you typed in the CODE into a text notepad then renamed it to "System Cleanup.bat" and right clicked it, then ran as administrator.....

    it didn't do a thing :(
     
  5. Spartan@HIDevolution

    Spartan@HIDevolution Company Representative

    Reputations:
    39,567
    Messages:
    23,559
    Likes Received:
    36,826
    Trophy Points:
    931
    Ahh ok, so I just created a blank text file with this code:

    then saved the file as System Cleanup.ps1

    Then I right clicked on it and chose Run As Admin, not a single file got deleted, what's going on
     
  6. JOSEA

    JOSEA NONE

    Reputations:
    4,013
    Messages:
    3,521
    Likes Received:
    170
    Trophy Points:
    131
  7. John Ratsey

    John Ratsey Moderately inquisitive Super Moderator

    Reputations:
    7,197
    Messages:
    28,839
    Likes Received:
    2,162
    Trophy Points:
    581
    Alternatively, get ccleaner which will clean up the temp files and a lot more.

    John
     
    Ferris23 likes this.
  8. Spartan@HIDevolution

    Spartan@HIDevolution Company Representative

    Reputations:
    39,567
    Messages:
    23,559
    Likes Received:
    36,826
    Trophy Points:
    931
    As I mentioned in my OP, I have been getting Indexing corruption that is irrepairable every time I format and set my system up as I want......never figured out why, even rebuilding the Index doesn't help. Upon searching Google about this, I ran across a few posts of users who use CCleaner complaining that it is responsible for this. This was @ version 3.5 and they said they fixed the issue but now I wanna try without CCleaner to see how it goes this time
     
  9. Spartan@HIDevolution

    Spartan@HIDevolution Company Representative

    Reputations:
    39,567
    Messages:
    23,559
    Likes Received:
    36,826
    Trophy Points:
    931
    Finally got it! A guy from MDL forums gave me the text I would have never been able to figure it out! Tested it and working perfectly to remove the files from USER Temps + Software Distribution Download Folder (Temp Windows Update Files) + Windows Temp files

    Paste this in a text file and rename it to whatever you want.bat and run it as admin!

    Code:
    DEL /S /F /Q "%temp%\*" 1>nul 2>nul
    DEL /S /F /Q %systemroot%\temp\* 1>nul 2>nul
    DEL /S /F /Q %systemroot%\SoftwareDistribution\Download\* 1>nul 2>nul
    for /f %%i in ('"dir /s /b /ad "%temp%"" 2^>nul') do RD /S /Q %%i 1>nul 2>nul
    for /f %%i in ('"dir /s /b /ad %windir%\temp" 2^>nul') do RD /S /Q %%i 1>nul 2>nul
    for /f %%i in ('"dir /s /b /ad %windir%\SoftwareDistribution\Download" 2^>nul') do RD /S /Q %%i 1>nul 2>nul
     
  10. HTWingNut

    HTWingNut Potato

    Reputations:
    21,580
    Messages:
    35,370
    Likes Received:
    9,877
    Trophy Points:
    931
    Just use Windows Disk Cleanup or Ccleaner or Glary Utilities. I find Glary is the most thorough. They all have a reasonably intuitive GUI and most importantly all free. No need to use a batch file when these apps do the same and better.
     
  11. Spartan@HIDevolution

    Spartan@HIDevolution Company Representative

    Reputations:
    39,567
    Messages:
    23,559
    Likes Received:
    36,826
    Trophy Points:
    931
    Batch file is faster for me

    Here is a more advanced batch script that cleans out more folders (got it from MDL forums and works great):

    Code:
    [b]@echo off
    title .
    color 1F
    openfiles >nul 2>&1
    if %errorlevel% NEQ 0 goto :UACPrompt
    goto :gotAdmin
    
    :UACPrompt
        echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
        echo UAC.ShellExecute "%~fs0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
        "%temp%\getadmin.vbs"
        del "%temp%\getadmin.vbs"
        exit /b
    
    :gotAdmin
    DEL /S /F /Q "%temp%\*" 1>nul 2>nul
    DEL /S /F /Q %systemroot%\temp\* 1>nul 2>nul
    DEL /S /F /Q %systemroot%\inf\*.log 1>nul 2>nul
    DEL /S /F /Q %systemroot%\Logs\CBS\* 1>nul 2>nul
    DEL /S /F /Q %systemroot%\Logs\DPX\* 1>nul 2>nul
    DEL /S /F /Q %systemroot%\Logs\DISM\* 1>nul 2>nul
    DEL /S /F /Q %systemroot%\Microsoft.NET\Framework\v2.0.50727\*.log 1>nul 2>nul
    DEL /S /F /Q %systemroot%\Microsoft.NET\Framework\v4.0.30319\*.log 1>nul 2>nul
    if exist %systemroot%\SysWOW64\cmd.exe DEL /S /F /Q %systemroot%\Microsoft.NET\Framework64\v2.0.50727\*.log 1>nul 2>nul
    if exist %systemroot%\SysWOW64\cmd.exe DEL /S /F /Q %systemroot%\Microsoft.NET\Framework64\v4.0.30319\*.log 1>nul 2>nul
    DEL /S /F /Q %systemroot%\SoftwareDistribution\Download\* 1>nul 2>nul
    RD /S /Q "%LocalAppData%\Microsoft\Windows\WER\ReportQueue" 1>nul 2>nul
    for /f %%i in ('"dir /s /b /ad "%temp%"" 2^>nul') do RD /S /Q %%i 1>nul 2>nul
    for /f %%i in ('"dir /s /b /ad %windir%\SoftwareDistribution\Download" 2^>nul') do RD /S /Q %%i 1>nul 2>nul
    for /f %%i in ('"dir /s /b /ad %windir%\temp" 2^>nul') do RD /S /Q %%i 1>nul 2>nul[/b]