How to Delete Files from a Folder When Turning off the PC

Everything related to the storage units on our Windows computer is something that is increasingly worrying. This is because when they fill almost completely, something that usually happens, we have a problem. That is why in these lines we are going to show you how to delete files from a folder when Windows automatically turns off.

It is true that with the passage of time, these hard drives and SSDs that we are talking about, have gained in capacity. But in parallel, every time we work with a greater amount of data and applications in Windows, so we continue to fill them anyway. This is something that most of you have surely faced on more than one occasion, so you will know how annoying it is to free up space, by hand. For this we can use several methods, as we have commented on several occasions.

Delete Files from a Folder When Turning off the PC

How to free up space in Windows manually

One of the most common systems that we usually use is to delete files from Windows itself and its programs that are unnecessary. Here we talk about temps, everything in the Recycle Bin, etc. This can sometimes be a good amount of space freed up, even several gigabytes at times. This is due to the large number of storms generated by apps such as Spotify or some video programs.

On the other hand, we also usually use the Control Panel to search for programs that we have installed, but that we have not used for a long time. And it is that in the uninstaller of applications of Windows itself, we find a list of these to double click on those that we want to eliminate.

Desinstalar programas panel

In the same way, we can also opt for the decision to delete saved files that take up a lot of space, such as HD videos or music libraries. Or instead of deleting all that, at least save it on an external storage unit to play whenever we want, but without wasting space on the PC drives.

Empty a folder when shutting down Windows automatically

But in these same lines or we are going to show another way to free up space every time we turn off the PC, which can be very useful for some. For example, as we mentioned before, there are certain programs that by themselves generate a huge amount of temporary files that are useless. Here you can accumulate up to several gigs if we make continuous use of them. We can highlight the case of the aforementioned Spotify, video editing programs when loading large content, 3D applications , etc.

That is why, to save space, we can empty a folder when Windows automatically shut down, that is, the one we want, like those temporary ones. And it is that on many occasions and for a matter of order, many of us create a specific folder to place these temporary files. The same are needed while we work with certain programs. Therefore, once we finish the session, we tend to empty, sometimes, this folder every time we turn off the computer.

But here we are going to show you that in Windows, we have the possibility of automatically deleting the contents of a folder when the computer is turned off. Well, for all this, what we will do is use the Local Group Policy Editor of the operating system itself. For those of you who are unfamiliar with it, this is an advanced feature offered by Windows that allows you to run Windows scripts both on startup and shutdown. Thus, in this case we are going to take advantage of all this to execute a script that eliminates the content of a folder that we indicate and empties it when the PC is turned off.

Create a script to delete files from a folder

First of all, what we will do to delete files from a folder automatically, is the script itself. This will be a batch file that will take care of all of it. An example is a batch file like the one shown below: del / q C: / Users / softzone / temporal / *.

To give us an idea, what we are actually doing here is deleting all the contents of the C: / Users / softzone / temporary / folder. Of course, here what we have to do is adapt the path according to the location of the folder that we want to delete on our computer. In the case that the folders we specify have more than one word, we write them in quotes. In turn, when you type del, this is the Windows command to delete files, while / q is an option to delete files without confirmation.

This is something we can write in Windows Notepad and save the new script in a batch file with the extension of .bat. For example, we can call it Borrartemporales.bat. In addition, this is something that we can save anywhere, for example on the desktop.

script temporales borrar archivos

Use Local Group Policy Editor to delete files

Well, once we have created the batch file that we have just shown you, we press the Win + R key combination on the keyboard. This helps us to open the Run dialog box, where we type gpedit.msc . Then the Local Group Policy Editor window will open, an element that we certainly cannot find in Windows 10 Home.

Here we are going to find the aforementioned group policy window, where we first go to Computer Configuration. Next we will have to go to Windows Settings in order to double-click on the Scripts option (Start / Shutdown) in the right panel.

Scripts inicio apagado borrar archivos

At that moment we have to double click on the Shutdown option and click on the Add button to add a new script when shutting down the Windows PC.

Agregar nuevo script

Now we just have to click on the Browse button in the Script Name section to find the batch file that we just created. On the other hand, the Script Parameters are optional, so we can leave them empty, and everything is ready. From that moment on, the indicated folder will be deleted by itself when Windows is shut down.

Seleccionar script

In the event that this does not work, we can carry out the same process described to delete files, but adding the script elsewhere in the group policies . Specifically in the User Configuration / Windows Configuration. Here we can already double-click on the Scripts option (Login or logout).

cierre de sesión script borrar archivos

We double click on the Close session option, and as before, we add the new script that we have created.