DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: Script to remove windows.old folder  (Read 8,770 times)

glasskuter

  • Supporting Member
  • Joined in 2015
  • **
  • Posts: 4
Script to remove windows.old folder
« on: August 26, 2015, 06:06 PM »
Hello again guys,
I offer a community service to assist a lot of people remotely so don't always have hands on systems I deal with. There is a problem when it comes to deleting the Windows.old folder after one has upgraded to Windows 10. I have found that using disk cleanup works to remove this folder completely if the system is BIOS based.  However, if the upgraded system is UEFI based, the windows.old folder will not completely remove.  It leaves two folders relating to driverstore. Using elevated command will not remove the folder either as it responds with "access denied". I have tried changing privileges on the folder which also doesn't work. The only way I have found to completely get rid of the remaining 2 folders within windows.old is to use the command line at boot which I can't do remotely.

I found a script on the net which is quite old and not being familiar with code I am somewhat confused by it and what I am supposed to enter into the script.  The person who wrote the script is not as proficient as you guys when it comes to simplifying instructions for script dummies like me. Would you take a look at the attached script and clarify if it is valid and if it will work to achieve my goal of completely getting rid of the windows.old folder.
Assume in your response that the path to the windows.old folder is c:\windows.old.
Thanks for your superior work.

tomos

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 11,970
    • Gathering Badge
    • Participated in NANY Challenge Once
Re: Script to remove windows.old folder
« Reply #1 on: August 26, 2015, 07:14 PM »
just making the script more accessible
(I'm not sure though if that's the right type of formatting)

Code: (actionscript)
REM JK-Windows.Old Deleter Version 1.0.181109 by jkadeesh
@echo off
setlocal
Title Windows.Old Deleter
set BAT_HOME=%~dp0
set BAT_NAME=%~s0
set BATFILE=%~nx0
set DRVLET=%~d0

if "%1"=="" goto interactive
REM Flash related lines are meant for deleting Flash specific .OCX files which cannot be easily deleted
if exist %1\Windows\System32\Macromed\Flash CD /D %1\Windows\System32\Macromed\Flash && cacls *.* /P Everyone:F
cd /d %DRVLET%
takeown /f %1 /R /d y
icacls %1 /grant administrators:F /t
rd /s /q %1
goto end

:interactive
cls
cd /d %DRVLET%\
IF EXIST %DRVLET%\Windows.old ECHO. && ECHO Found %DRVLET%\Windows.old && GOTO Auto
IF NOT EXIST %DRVLET%\Windows.old ECHO. && ECHO NOT FOUND %DRVLET%\Windows.old && ECHO.

echo Enter folder name [with complete path] which needs to be deleted:   do i enter \c: \windows.old here in script??
echo.
echo To exit type "x" and press Enter key
echo.
echo.
set /p user=Folder Name[with path]: I’m confused about what to enter here
if "%user%"=="x" goto end

if exist %user%\Windows\System32\Macromed\Flash CD /D %user%\Windows\System32\Macromed\Flash && cacls *.* /P Everyone:F
cd /d %DRVLET%\
takeown /f %user% /R /d y
icacls %user% /grant administrators:F /t
rd /s /q %user%

if not "%user%"=="x" goto interactive
goto end

:Auto
cls
ECHO.
cd /d %DRVLET%\
set user=Windows.old
if exist %DRVLET%\%user%\Windows\System32\Macromed\Flash CD /D %DRVLET%\%user%\Windows\System32\Macromed\Flash && cacls *.* /P Everyone:F
cd /d %DRVLET%\
takeown /f %user% /R /d y
icacls %user% /grant administrators:F /t
rd /s /q %user%

goto end
:end
ECHO.
ECHO Exiting...
ECHO.
pause

Quote
How to use the above code?
0. Disable User Access control [temporarily] - Once this task of deleting files / folders is completed,
you may want to re-enable User Access Control. To disable UAC,
go to Control Panel > User Accounts > Turn User Account Control on or off ; then uncheck the
option "Use User Account Control (UAC) to help protect your computer" and click OK. Then restart the computer.
1. Copy/paste the code to Notepad
2. Save the file with the file name as: DeleteFiles.bat to C:\ drive [any location is ok - you need
to go to the relevant location using the command line in step: 4]
Note that the 'Save as type' should be selected as "All Files (*.*)" before you click the Save button.
3. Go to Command prompt
4. Type CD \  to go to C:\
5. Type DeleteFiles foldername and then press Enter key
By default, the folder name is C:\Windows.old.
If the Windows.old folder resides in D:\ [or a different drive], then enter the drive letter accordingly
along with the folder name.
6. Then you will notice a lot of operation in the command window and the script will end with
"Exiting..." . Press any key to exit the script.
Then you will find Windows.old folder is completely removed - Note that with this method the
contents of Windows.old folder will not won't be sent to the Recycle bin.
DeleteFiles.bat can be run without supplying the folder name also - in that scenario, it will
consider Windows.old folder present in the current drive from which you run the batch file
Tom

Original address: https://www.donationcoder.com/forum/index.php?topic=41500.0