fraunkd
asked on
Script - Remove Temp Files For ALL Profiles
I have a terminal server with cookies, temp, and temporary internet files that I would like to remove for ALL profiles within documents and settings.
I’d like to create a script that will run each day to remove the files.
The bat file I have created only removes the temp files from the profile of the user that’s currently logged on – and skipping the rest of the profiles within documents and settings as desired.
Below is my script. Please let me know the best way to write this to where all profiles are cleaned rather than only the profile of the logged on user. Thanks.
del "C:\documents and settings\%username%\cookie s\*.*" /Q
del "C:\documents and settings\%username%\Local Settings\temp\*.*" /Q
del "C:\documents and settings\%username%\Local Settings\temporary internet files\*.*" /Q
I’d like to create a script that will run each day to remove the files.
The bat file I have created only removes the temp files from the profile of the user that’s currently logged on – and skipping the rest of the profiles within documents and settings as desired.
Below is my script. Please let me know the best way to write this to where all profiles are cleaned rather than only the profile of the logged on user. Thanks.
del "C:\documents and settings\%username%\cookie
del "C:\documents and settings\%username%\Local Settings\temp\*.*" /Q
del "C:\documents and settings\%username%\Local Settings\temporary internet files\*.*" /Q
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
billprew
When I remove ECHO, I receive the line below multiple times:
The filename, directory name, or volume label syntax is incorrect.
When I remove ECHO, I receive the line below multiple times:
The filename, directory name, or volume label syntax is incorrect.
ASKER
Below is what worked best:
https://www.experts-exchange.com/questions/20794666/Batch-file-to-delete-temporary-internet-files-and-others.html
cls
SET SRC1=%SYSTEMDRIVE%\Documen ts and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\Temp
SET SRC4=Local Settings\History
SET SRC5=%SYSTEMROOT%\Temp
SET SRC6=Cookies
echo About to delete files from Internet Explorer "Temporary Internet files"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
echo About to delete files from "Local settings\temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Windows\Temp"
cd\
%systemdrive%
cd /d %SystemRoot%\temp
del /F /Q *.*
@echo Y|RD /S ""
@echo.
@echo.
echo About to delete files from "Local Settings\History"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\today*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "%SYSTEMROOT%\Temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC5%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Cookies"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC6%\*.*") DO DEL /F /S /Q "%%Y"
@echo Please review any errors if they exist
@echo.
@echo.
https://www.experts-exchange.com/questions/20794666/Batch-file-to-delete-temporary-internet-files-and-others.html
cls
SET SRC1=%SYSTEMDRIVE%\Documen
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\Temp
SET SRC4=Local Settings\History
SET SRC5=%SYSTEMROOT%\Temp
SET SRC6=Cookies
echo About to delete files from Internet Explorer "Temporary Internet files"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
echo About to delete files from "Local settings\temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Windows\Temp"
cd\
%systemdrive%
cd /d %SystemRoot%\temp
del /F /Q *.*
@echo Y|RD /S ""
@echo.
@echo.
echo About to delete files from "Local Settings\History"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\today*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "%SYSTEMROOT%\Temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC5%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Cookies"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC6%\*.*") DO DEL /F /S /Q "%%Y"
@echo Please review any errors if they exist
@echo.
@echo.
ASKER
This is what worked best:
cls
SET SRC1=%SYSTEMDRIVE%\Documen ts and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\Temp
SET SRC4=Local Settings\History
SET SRC5=%SYSTEMROOT%\Temp
SET SRC6=Cookies
echo About to delete files from Internet Explorer "Temporary Internet files"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
echo About to delete files from "Local settings\temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Windows\Temp"
cd\
%systemdrive%
cd /d %SystemRoot%\temp
del /F /Q *.*
@echo Y|RD /S ""
@echo.
@echo.
echo About to delete files from "Local Settings\History"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\today*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "%SYSTEMROOT%\Temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC5%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Cookies"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC6%\*.*") DO DEL /F /S /Q "%%Y"
@echo Please review any errors if they exist
@echo.
@echo.
cls
SET SRC1=%SYSTEMDRIVE%\Documen
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\Temp
SET SRC4=Local Settings\History
SET SRC5=%SYSTEMROOT%\Temp
SET SRC6=Cookies
echo About to delete files from Internet Explorer "Temporary Internet files"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
echo About to delete files from "Local settings\temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Windows\Temp"
cd\
%systemdrive%
cd /d %SystemRoot%\temp
del /F /Q *.*
@echo Y|RD /S ""
@echo.
@echo.
echo About to delete files from "Local Settings\History"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\today*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "%SYSTEMROOT%\Temp"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC5%\*.*") DO DEL /F /S /Q "%%Y"
echo About to delete files from "Cookies"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC6%\*.*") DO DEL /F /S /Q "%%Y"
@echo Please review any errors if they exist
@echo.
@echo.
==> When I remove ECHO, I receive the line below multiple times:
What did it look like before you removed the ECHO?
(although I guess it's moot at this point)
~bp
What did it look like before you removed the ECHO?
(although I guess it's moot at this point)
~bp
Can sombody show me how to make this for windows 7
regards Jan sejer
regards Jan sejer
Notice the DEL lines have ECHO in front of them right now. This will let you test this out without deleting anything, it will just echo the DEL command that would have been executed to the scree so you can check it out. Once you get it perfect, remove the ECHOs in front of the DEL commands.
~bp
Open in new window