Temp folder: cleaning with a script

An active operating system, whether it be Windows or Unix, is always a lot of newly created files, which are commonly called temporary, in Russian - temporary. These may be intermediate results of Photoshop, Nero, Open Office, Internet Explorer, Firefox, and various system programs. For camouflage purposes, viruses are also preserved. There are several directories on the hard drive under the single name Temp, in which these files are stored.

Firstly, simply on the C: drive, then in the Windows folder, as well as in Documents and Settings (subdirectory Local Settings). In addition, the location of the Temp files depends on the β€œbrand” of Windows installed on your PC. For example, in Windows Seven they are stored in six different ways.

Over the months of using a PC, the Temp folder has grown to rampant sizes, amounting to hundreds of useless megabytes, so it would be nice to set it to clean up! At the same time, defragment the hard drive. You can implement this in every possible way. For the average user, it is easiest to run special utilities that allow you to clean up temporary files. The most popular of these are Ccleaner and Glary Utilites.

You can also use a standard system cleaner. In Windows XP and later, this method is approximately the same in execution. Just go to the properties of the disk in the "Explorer" (by right-clicking on the selected drive C :) and click on the "Disk Cleanup" button . The main disadvantage of this method is that not all files are deleted.

The disadvantage is eliminated using the already listed third-party utilities. In addition to this method, you can use the browser function, because Temporary Internet Files are one of the types of "junk" files, sometimes they accumulate more than the Temp folder, and take up considerable space on the hard drive.

For Firefox, you can use Tools> Erase History. You must select cookies and cache. If you are still using Internet Explorer, then there you can delete temporary files using the "Internet Options" icon on the control panel. The name of the subsection that you need is "Temporary Internet Files". To clean directories, use a couple of buttons - "Delete cookies" and "Delete files".

So, we described how to remove temporary files from Windows 7 and previous generation systems for mere mortals. But there are still methods that programmers and administrators apply. Most often they use scripts. You too can follow this example. The unique advantages of scripts are automation. Let's look at how you can get rid of temporary files with the help of embedding and regular script execution. Take the most relevant system to date - Windows 7.

1. Create a Temp Folder object in the root of the C: drive.

2. With the right mouse button, go to the properties of the My Computer icon, the bottommost item, the Advanced tab. Select the "Environment Variables" button . You need to change the value of the TMP and TEMP variables to the path C: \ Temp.

3. Then, in the notebook, write the following lines: pushd% TEMP% && rd / s / q. > nul 2> & 1 pushd C: \ TEMP && rd / s / q. > nul 2> & 1. Save the file under the name cleartmp.cmd strictly with the specified extension directly to the C: drive.

4. Using the policy editor (starting from "Start"> "Run"> "gpedit.msc") adds a script to the system using the "Windows Configuration" tab of the " Computer Configuration " section . There you need to select "Startup / Shutdown Scripts" and go to the "Shutdown" item properties. After that, using the "Add" button, we show the path to the script, which will clear the temporary folder.

5. The section "User Configuration" (tab "Windows Configuration"> "Scripts Startup / Shutdown"> "Shutdown") is subjected to the same processing. Most likely, you already understood that upon completion of all the indicated points the Temp folder will be cleaned each time the computer shuts down, you do not need to run the program. Of course, you can implement such a script using the task manager, but this is already much larger than the expected volume of this article.

Source: https://habr.com/ru/post/C42841/


All Articles