{"id":1660,"date":"2022-02-08T14:00:54","date_gmt":"2022-02-08T12:00:54","guid":{"rendered":"https:\/\/helia.ee\/koolitus\/?page_id=1660"},"modified":"2022-02-08T14:00:54","modified_gmt":"2022-02-08T12:00:54","slug":"microsoft-windows-how-to-delete-files-older-than-x-days-automatically-on-windows-10","status":"publish","type":"page","link":"https:\/\/helia.ee\/koolitus\/?page_id=1660","title":{"rendered":"Microsoft Windows &#8211; How to delete files older than X days automatically on Windows 10"},"content":{"rendered":"<div class=\"article-header\">\n<header class=\"entry-header\">\n<h1 class=\"entry-title\">How to delete files older than X days automatically on Windows 10<\/h1>\n<div class=\"post-description\">\n<div class=\"post-description-content\">\n<p>You can free up space and keep things organized by only deleting files that are older than a certain number of days in any folder \u2014 here&#8217;s how to do it.<\/p>\n<\/div>\n<\/div>\n<div class=\"entry-meta meta-gravatar\">\n<div class=\"author_and_date\">\n<div id=\"author-time\">\n<div class=\"author-time\"><\/div>\n<div><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/header>\n<\/div>\n<div class=\"article-content-wrapper\">\n<div class=\"article-content-inner\">\n<div class=\"article-presentation\">\n<div class=\"article-hero-image\">\n<figure class=\"article_image\"><img loading=\"lazy\" decoding=\"async\" class=\"attachment-large size-large wp-post-image\" src=\"https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/delete-older-than-files-windows-10-976x574.jpg\" sizes=\"auto, (max-width: 827px) 100vw, 827px\" srcset=\"https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/delete-older-than-files-windows-10-976x574.jpg 976w, https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/delete-older-than-files-windows-10-300x176.jpg 300w, https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/delete-older-than-files-windows-10.jpg 1580w\" alt=\"Delete older than files on Windows 10\" width=\"827\" height=\"486\" \/><\/figure>\n<\/div>\n<\/div>\n<div class=\"article-main-content\">\n<aside class=\"top-rvzone\"><\/aside>\n<div class=\"share-buttons\"><\/div>\n<div id=\"KonaBody\" class=\"entry-content\" data-first_letter=\"O\">\n<ul class=\"toc\">\n<li><\/li>\n<\/ul>\n<h2 id=\"forfiles_delete_command\">How to use ForFiles to delete files older than X days on Windows 10<\/h2>\n<p>If you have different folders with many files and you would like to\u00a0<span class=\"vm-hook-outer\"><span class=\"vm-hook\">clean<\/span><\/span>\u00a0up by deleting those files that are older than a certain number of days, you can use the ForFiles command.<\/p>\n<p>To use the ForFiles command to delete files older than a certain number of days, use these steps:<\/p>\n<ol>\n<li>Open\u00a0<strong>Start\u00a0<\/strong>on Windows 10.<\/li>\n<li>Search for\u00a0<strong>Command Prompt<\/strong>, right-click the result and select the\u00a0<strong>Run as administrator<\/strong>\u00a0option.<\/li>\n<li>T<span class=\"vm-hook-outer\"><span class=\"vm-hook\">ype\u00a0<\/span><\/span>the following command to delete files that haven\u2019t been modified in the last 30 days and press\u00a0<strong>Enter<\/strong>:\n<pre>ForFiles \/p \"C:\\path\\to\\folder\" \/s \/d -30 \/c \"cmd \/c del \/q @file\"<\/pre>\n<p>In the above command remember to change\u00a0<code>\"C:\\path\\to\\folder\"<\/code>\u00a0specifying the path to the folder you want to delete\u00a0<span class=\"vm-hook-outer\"><span class=\"vm-hook\">files<\/span><\/span>\u00a0and change\u00a0<code>\/d -30<\/code>\u00a0to select files with a last modified\u00a0<span class=\"vm-hook-outer\"><span class=\"vm-hook\">date<\/span><\/span>.<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_93447\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-93447\" src=\"https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/forfiles-delete-files-windows10-cmd.jpg\" sizes=\"auto, (max-width: 830px) 100vw, 830px\" srcset=\"https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/forfiles-delete-files-windows10-cmd.jpg 830w, https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/forfiles-delete-files-windows10-cmd-300x82.jpg 300w\" alt=\"ForFiles using Command Prompt\" width=\"830\" height=\"227\" \/><figcaption class=\"wp-caption-text\">ForFiles using Command Prompt<\/figcaption><\/figure>\n<\/li>\n<\/ol>\n<h3>ForFiles command breakdown<\/h3>\n<ul>\n<li><strong>\/p \u2014<\/strong>\u00a0indicates the pathname to start searching.<\/li>\n<li><strong>\/s \u2014<\/strong>\u00a0instructs ForFiles to search inside subdirectories.<\/li>\n<li><strong>\/d \u2014<\/strong>\u00a0specifies the last modified date for a file.<\/li>\n<li><strong>\/c \u2014<\/strong>\u00a0instructs ForFiles to execute the command, which must be wrapped in double-quotes. The default is\u00a0<strong>\u201ccmd \/c del @file\u201d<\/strong>.<\/li>\n<li><strong>\/q<\/strong>\u00a0\u2014 allows deleting folders without requiring confirmation.<\/li>\n<\/ul>\n<p>If you want to learn more about these switches, use the\u00a0<code>ForFiles \/?<\/code>\u00a0Command.<\/p>\n<h2 id=\"forfiles_delete_command_taskscheduler\">How to use Task Scheduler to delete files older than X days automatically on Windows 10<\/h2>\n<p>The command in the previous instructions allows you to delete files in a folder older than 30 days, but you need to open Command Prompt and execute the command manually every time you want to free up\u00a0<span class=\"vm-hook-outer\"><span class=\"vm-hook\">space<\/span><\/span>.<\/p>\n<p>If you want to automate the process, you need to use the Task Scheduler on\u00a0<span class=\"vm-hook-outer\"><span class=\"vm-hook\">Windows 10<\/span><\/span>\u00a0to create a task that executes the command at specified intervals.<\/p>\n<p>To create a scheduled task with the ForFiles commands to delete files that haven\u2019t changed in some time, use these steps:<\/p>\n<ol>\n<li>Open\u00a0<strong>Start<\/strong>.<\/li>\n<li>Search for\u00a0<strong>Task Scheduler<\/strong>\u00a0and click the top result to open the\u00a0<span class=\"vm-hook-outer\"><span class=\"vm-hook\">experience<\/span><\/span>.<\/li>\n<li>Right-click the\u00a0<strong>Task Scheduler Library<\/strong>\u00a0folder.<\/li>\n<li>Click the\u00a0<strong>New Folder<\/strong>\u00a0option.<\/li>\n<li>Type any name for the folder and click\u00a0<strong>OK<\/strong>. (We\u2019re creating a new folder to keep tasks organized and separated from the system tasks.)<\/li>\n<li>Right-click the recently created folder and select the\u00a0<strong>Create Task\u00a0<\/strong>option.<\/li>\n<li>In the \u201cName\u201d box, enter a name for the task.<\/li>\n<li>In the \u201cGeneral\u201d tab, under the \u201cSecurity options\u201d section, select the \u201c<strong>Run whether user is logged on or not\u201d<\/strong>\u00a0option. (This option will make the command window not appear when the task runs automatically.)\n<p>&nbsp;<\/p>\n<figure id=\"attachment_93448\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-93448\" src=\"https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/create-task-general.jpg\" sizes=\"auto, (max-width: 632px) 100vw, 632px\" srcset=\"https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/create-task-general.jpg 632w, https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/create-task-general-300x228.jpg 300w\" alt=\"Task Scheduler General tab\" width=\"632\" height=\"480\" \/><figcaption class=\"wp-caption-text\">Task Scheduler General tab<\/figcaption><\/figure>\n<\/li>\n<li>Clear the\u00a0<strong>Do not store password<\/strong>\u00a0option.<\/li>\n<li>Click the \u201cTriggers\u201d tab, and click the\u00a0<strong>New<\/strong>\u00a0button.<\/li>\n<li>Using the \u201cBegin the task\u201d drop-down\u00a0<span class=\"vm-hook-outer\"><span class=\"vm-hook\">menu<\/span><\/span>, select the\u00a0<strong>On a schedule\u00a0<\/strong>option.<\/li>\n<li>Under \u201cSettings,\u201d specify when you want the task to run (e.g., On time, Daily, Weekly, Monthly). Whatever option you select, make sure to specify the\u00a0<strong>Start<\/strong>\u00a0settings on the right side.<\/li>\n<li>Click the\u00a0<strong>OK\u00a0<\/strong>button.\n<p>&nbsp;<\/p>\n<figure id=\"attachment_93449\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-93449\" src=\"https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/trigger-schedule-task.jpg\" sizes=\"auto, (max-width: 591px) 100vw, 591px\" srcset=\"https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/trigger-schedule-task.jpg 591w, https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/trigger-schedule-task-300x262.jpg 300w\" alt=\"Task Scheduler Trigger settings\" width=\"591\" height=\"516\" \/><figcaption class=\"wp-caption-text\">Task Scheduler Trigger settings<\/figcaption><\/figure>\n<\/li>\n<li>Click the \u201cActions\u201d tab, and click the\u00a0<strong>New<\/strong>\u00a0Button.<\/li>\n<li>Using the \u201cActions\u201d drop-down menu and select the\u00a0<strong>Start a program\u00a0<\/strong>option.<\/li>\n<li>In the \u201cProgram\/script\u201d box, type the following command:\n<pre>ForFiles<\/pre>\n<\/li>\n<li>Type the following command in the \u201cAdd arguments\u201d box and click the\u00a0<strong>OK\u00a0<\/strong>button.\n<pre>\/p \"C:\\path\\to\\folder\" \/s \/d -30 \/c \"cmd \/c del \/q @file\"<\/pre>\n<p>In the above command remember to change\u00a0<code>\"C:\\path\\to\\folder\"<\/code>\u00a0specifying the path to the\u00a0<span class=\"vm-hook-outer\"><span class=\"vm-hook\">folder<\/span><\/span>\u00a0that you want to delete files and change\u00a0<code>\/d -30<\/code>\u00a0to select files with a last modified date.<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_93450\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-93450\" src=\"https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/forfiles-action-task-scheduler.jpg\" sizes=\"auto, (max-width: 454px) 100vw, 454px\" srcset=\"https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/forfiles-action-task-scheduler.jpg 454w, https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/forfiles-action-task-scheduler-272x300.jpg 272w\" alt=\"Task Scheduler Action settings\" width=\"454\" height=\"500\" \/><figcaption class=\"wp-caption-text\">Task Scheduler Action settings<\/figcaption><\/figure>\n<\/li>\n<li>Click the\u00a0<strong>OK<\/strong>\u00a0button.<\/li>\n<li>Click the \u201cSettings\u201d tab, and make sure to check the following options:\n<ul>\n<li>Allow task to be run on demand.<\/li>\n<li>Run task as soon as possible after a scheduled start is missed.<\/li>\n<li>If the task fails, restart every.<\/li>\n<\/ul>\n<\/li>\n<li>Click the\u00a0<strong>OK\u00a0<\/strong>button.\n<p>&nbsp;<\/p>\n<figure id=\"attachment_93451\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-93451\" src=\"https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/task-settings-options-windows10.jpg\" sizes=\"auto, (max-width: 632px) 100vw, 632px\" srcset=\"https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/task-settings-options-windows10.jpg 632w, https:\/\/i3g4v6w8.stackpathcdn.com\/wp-content\/uploads\/2017\/10\/task-settings-options-windows10-300x228.jpg 300w\" alt=\"Task Scheduler additional settings\" width=\"632\" height=\"480\" \/><figcaption class=\"wp-caption-text\">Task Scheduler additional settings<\/figcaption><\/figure>\n<\/li>\n<li>If prompted, enter your administrative\u00a0<span class=\"vm-hook-outer\"><span class=\"vm-hook\">username<\/span><\/span>\u00a0and password.<\/li>\n<li>Click the\u00a0<strong>OK\u00a0<\/strong>button.<\/li>\n<\/ol>\n<p>Once you complete the steps, the command will run on the schedule deleting the files in the location older than the number of days you specified. Remember not to change the name or move the folder to another location. Otherwise, the task will fail.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>How to delete files older than X days automatically on Windows 10 You can free up space and keep things organized by only deleting files that are older than a certain number of days in any folder \u2014 here&#8217;s how to do it. How to use ForFiles to delete files older than X days on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":841,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"class_list":["post-1660","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages\/1660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1660"}],"version-history":[{"count":1,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages\/1660\/revisions"}],"predecessor-version":[{"id":1661,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages\/1660\/revisions\/1661"}],"up":[{"embeddable":true,"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=\/wp\/v2\/pages\/841"}],"wp:attachment":[{"href":"https:\/\/helia.ee\/koolitus\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}