Need script to delete files, folders, and subfolders
Hello all,
I am new to the KACE world. I am hoping the community can assist me. I need a script that will do the following:
Delete any file or folder that is within any temp folder (including the temp folders in the users profile i.e., C:\Users\%USERNAME%\AppData\Local\Temp) need to be deleted. Also all files and subĀ folders within the download folder. I work in an environment where we need the ability to clean these folders out on a regular schedule.
I am terrible with scripting but would am willing to learn. Any assistance will be appreciated.
Mr. Newbie!
2 Comments
[ + ] Show comments
-
Are you sure you want to delete the files for currently logged in users? - chucksteel 7 years ago
-
Maybe I wasn't as clear as I needed to be ;). Any file or folder that is within any temp folder (including the temp folders in the users profile i.e., C:\Users\%USERNAME%\AppData\Local\Temp) need to be deleted. Also all files and folder within the downloads folder. Work in an environment where we need the ability to clean these folders out on a regular schedule. - hallj22 7 years ago
Answers (1)
Please log in to answer
Posted by:
Desktop Jockey
7 years ago
Here is a Batch file solution:
(
for /D %%x in ("C:\Users\*") do (
del /f /q "%%x\AppData\Local\Temp\*.*"
)
)
Comments:
-
That kind of works. It deleted most of the files within the temp folder but left all subfolders and files within. I have since figured out how to delete the files within the subfolders. I still need to figure out how to suppress everything from showing on the screen to the user and to also delete everything from the windows temp folder. I appreciate everyone's help.
(
for /D %%x in ("C:\Users\*") do (
del /f /s /q "%%x\AppData\LocalLow\Temp\*.*"
del /f /s /q "%%x\AppData\Local\Temp\*.*"
) - hallj22 7 years ago-
If you are running this from a Kace Script then it will be silent by default.
Also if you are having issues with the sub directories, you can add a rmdir command to that process. - Desktop Jockey 7 years ago-
I did read about the rmdir command but haven't had success with it yet. Scripting is not my strong suite. Appreciate the responses. - hallj22 7 years ago