How to Automatically Empty Folder Contents Upon Shutdown on Windows

HomeWindowsHow to Automatically Empty Folder Contents Upon Shutdown on Windows

How to Automatically Empty Folder Contents Upon Shutdown on Windows

For a neatness reason, some people create a specific folder to place the temporary files they need while working and empty this folder every time they shutdown the computer. In Windows, you can automatically delete the contents of a folder every time you shutdown your Windows computer. You can use Local Group Policy Editor to do so.

Local Group Policy Editor is an advanced feature offered by Windows that allows you run Windows scripts on both startup and shutdown. You can make use of this feature to run a script to delete the contents of a folder.

Automatically emptying folder contents upon shutdown on Windows

The first thing yo need to prepare to automatically delete the contents of a folder upon shutdown is the script (batch file) to delete the contents. In this example, we use a batch file with the following command line.

del /q  C:\Users\"Aliko Sunawang"\"temporary folder"\*

The command above will delete all contents under the temporary folder (full path C:\Users\”Aliko Sunawang”\”temporary folder”\). You can tailor the path according to the location of the folder you want to delete the contents of. Remove the quotation marks if your folder contains only a single word.

del on the script above is the Windows command to delete files, while q is an option to delete files without confirmation dialog.

You can save the script above in a batch file with the extension of .bat (example deletetempfolder.bat). You can save it anywhere.

Once you have create the batch file, press the Windows+R keys on keyboard to open the Run dialog and type gpedit.msc (Visit this page to download the cheat sheet of 118 Run Commands You Can Execute on Windows 10 ). On the Local Group Policy Editor window, select Computer Configuration -> Windows Settings and double-click the Scripts (Startup/Shutdown) option on the right panel.

Next, double-click the Shutdown option and click the Add button to add a new script upon shutdown.

Click the Browse button on the Script Name section to browse the batch file you have just create. Script Parameters is optional, you can leave it empty. Click the OK button followed by Add button.

Potential issues

If the the steps not working, try to add your script to the User Configuration section (still on the Local Group Policy Editor window). Select User Configuration -> Windows Settings and double click the Script(Logon/Logoff) option.

Double the Logoff option and add your script.

If still not working, try to check the Windows edition you use. Some Windows 10 users say Local Group Policy Editor doesn’t work on Windows 10 Pro and Ultimate editions.

hand-picked weekly content in your inbox


related posts


Please enter your comment!
Please enter your name here