How to delete files from a folder when turning off the PC

Share on facebook
Share on twitter
Share on linkedin
Share on reddit
Share on email
Share on whatsapp

It is true that with the passage of time, these hard drives and SSD of which we do not speak, 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.

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 sometimes. This is due to the large number of storms generated by apps such as, for example, 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.

Uninstall panel programs

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 files temporary that are of no use. 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 at the shut down windows automatically, that is, the one we want, like those of temporary. 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 of this to execute a script that eliminates the content of a folder that we indicate and empties itself at turn off the PC.

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 typing 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.

bat delete

It may also be the case that we want to delete a complete folder, where the subfolders included in it are also included. Therefore, for this we will have to follow the same steps that we have described before, but changing the command as such. Thus, in this other case we will use the following command followed by the desired disk path:

rmdir /s /q

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 key combination Win + R 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 startup shutdown delete files

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

Add new script

Now we only have to click on the Browse button in the Script Name section to find the batch file that we have 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 you turn off Windows.

Select script

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

logout script delete files

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