{"id":18515,"date":"2022-01-20T19:59:18","date_gmt":"2022-01-20T18:59:18","guid":{"rendered":"https:\/\/ekiwi-blog.de\/?p=18515"},"modified":"2023-08-19T09:46:29","modified_gmt":"2023-08-19T08:46:29","slug":"windows-delete-temp-folder-with-batch-file-autostart","status":"publish","type":"post","link":"https:\/\/ekiwi-blog.de\/en\/18515\/windows-delete-temp-folder-with-batch-file-autostart\/","title":{"rendered":"Windows: Delete temp folder with batch file + autostart"},"content":{"rendered":"<p>Automatic deletion of the temp folder in Windows with a batch file.<\/p>\n<p><!--more--><\/p>\n<p>In the Temp directory of Windows programs like to store files, which are needed for the operation of the program, but otherwise normally do not contain important data. For example, a program generates an HTML preview, the file is stored here and then opened in the browser.<\/p>\n<p>Over time, many files can accumulate here, which occupy memory space and are not necessary.  Windows itself brings two possibilities to delete the temp folder, the disk cleanup utility and the storage sense functionality. However, both options require some time to set these up. The disk cleanup utility must be run manually and the storage sense function runs from time to time and does not allow direct control.<\/p>\n<p>So let&#8217;s use a different approach, The typical content of the directory looks like this.<\/p>\n<p><a href=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_1.png\" alt=\"\" width=\"451\" height=\"392\" class=\"aligncenter size-full wp-image-18482\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_1.png 451w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_1-300x261.png 300w\" sizes=\"auto, (max-width: 451px) 100vw, 451px\" \/><\/a><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of content<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ekiwi-blog.de\/en\/18515\/windows-delete-temp-folder-with-batch-file-autostart\/#Video_tutorial\" >Video tutorial<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ekiwi-blog.de\/en\/18515\/windows-delete-temp-folder-with-batch-file-autostart\/#Batch_file_to_delete_the_temp_directory\" >Batch file to delete the temp directory<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ekiwi-blog.de\/en\/18515\/windows-delete-temp-folder-with-batch-file-autostart\/#Execute_automatically_at_system_startup\" >Execute automatically at system startup<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Video_tutorial\"><\/span>Video tutorial<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><iframe loading=\"lazy\" width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/HHc8lgPDn6M\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Batch_file_to_delete_the_temp_directory\"><\/span>Batch file to delete the temp directory<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>By means of a batch file you can also delete the directory regularly and quickly. Compared to disk cleanup, you save quite a bit of time here. The deletion takes only a few seconds with the batch file. <\/p>\n<p>The contents of the batch file:<\/p>\n<pre>\r\ndel \/s \/f \/q %Temp%\\*.*\r\nfor \/f %%f in ('dir \/ad \/b %Temp%\\') do rd \/s \/q %Temp%\\%%f\r\n<\/pre>\n<p>To do this, we copy the two lines into the Windows editor and save them with the file extension &#8220;.bat&#8221;.<\/p>\n<p><a href=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_2.png\" alt=\"\" width=\"436\" height=\"196\" class=\"aligncenter size-full wp-image-18484\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_2.png 436w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_2-300x135.png 300w\" sizes=\"auto, (max-width: 436px) 100vw, 436px\" \/><\/a><\/p>\n<p>If we run the batch file, all files and folders that can be deleted and are not currently in use will be deleted from the temp directory.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Execute_automatically_at_system_startup\"><\/span>Execute automatically at system startup<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>One possibility is to empty the temp directory at system startup. To do this, we add the script to the Windows startup folder. Press CTRL + R and paste &#8220;shell:startup&#8221; into the dialog.<\/p>\n<p><a href=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_3.png\" alt=\"\" width=\"399\" height=\"206\" class=\"aligncenter size-full wp-image-18486\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_3.png 399w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_3-300x155.png 300w\" sizes=\"auto, (max-width: 399px) 100vw, 399px\" \/><\/a><\/p>\n<p>We now insert the batch file into the folder. The command will now be <a href=\"https:\/\/ekiwi-blog.de\/en\/54162\/vba-outlook-macro-automatically-execute-on-email-receipt\/\" title=\"VBA Outlook macro automatically execute on email receipt\">executed automatically<\/a> at every system start.<\/p>\n<p><a href=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_4.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_4.png\" alt=\"\" width=\"714\" height=\"190\" class=\"aligncenter size-full wp-image-18488\" srcset=\"https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_4.png 714w, https:\/\/ekiwi-blog.de\/wp-content\/uploads\/2022\/01\/temp_4-300x80.png 300w\" sizes=\"auto, (max-width: 714px) 100vw, 714px\" \/><\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Automatic deletion of the temp folder in Windows with a batch file.<\/p>\n","protected":false},"author":1,"featured_media":14619,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1555],"tags":[1865,1559,1558],"class_list":["post-18515","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-en","tag-temp","tag-tutorial-en","tag-windows-en"],"_links":{"self":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts\/18515","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/comments?post=18515"}],"version-history":[{"count":0,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/posts\/18515\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/media\/14619"}],"wp:attachment":[{"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/media?parent=18515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/categories?post=18515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ekiwi-blog.de\/en\/wp-json\/wp\/v2\/tags?post=18515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}