Dos batch file delete files based date
Of course if there are lots of folders to be treated or if there are files from many days a scripted solution might be preferred. Your VBS solution should work where the powershell one can be a problem if powershell is not configured to run scripts, I think. This failed in Windows 7 and worked in Windows 8. Quote from: foxidrive on October 04, , AM. More OP's get abducted by aliens here than any other section of the Forums Quote from: patio on October 04, , PM.
Quote from: Squashman on October 04, , PM. Quote from: foxidrive on October 04, , PM. Run the following commands :. Ok was bored a bit and came up with this, which contains my version of a poor man's Linux epoch replacement limited for daily usage no time retention :. February : is hard-coded to 28 days. Bissextile years is a hell to add, really. It would need to be adapted for other settings or a run-time evaluation read sShortTime, user-bound configuration, configure proper field order in a filter and use the filter to extract the correct data from the argument.
Did I mention I hate this editor's auto-formating? So all the complicated batches could be in the trash bin. Also forfiles don't support UNC paths, so make a network connection to a specific drive.
Have a look at my answer to a similar question :. This deletes files older than a given date. I'm sure it can be modified to go back seven days from the current date. I recommend using his version instead. All this regarding forfiles. But if you are using Windows server forfiles. That is why I should modify command.
But command line interpreter cmd. Lots of good working solutions using additional console applications or scripts have been posted already here, on other pages of Stack Overflow and on other websites.
Very common is UTC. But any later day could be also used depending on the date range required to support for a specific task. Jay posted 7daysclean. But it does not take leap years correct into account. This very fast table method can be used also in batch code using FOR command. Note: Leap seconds are not taken into account as the Windows file systems also do not support leap seconds. Calculating the seconds for year to with epoch beginning is only possible with using an unsigned bit variable, i.
But cmd. The format of date and time strings depends on Windows region and language settings. Now the last 10 characters from date string are passed to function GetSeconds and therefore it does not matter if date string of environment variable DATE is with or without weekday as long as day and month are always with 2 digits in expected order, i.
For optimal performance it would be best to remove all comments, i. And the arrays can be made also smaller, i.
For even more information about date and time formats and file time comparisons on Windows see my answer on Find out if file is older than 4 hours in batch file with lots of additional information about file times. IMO, JavaScript is gradually becoming a universal scripting standard: it is probably available in more products than any other scripting language in Windows, it is available using the Windows Scripting Host.
I have to clean out old files in lots of folders, so here is a JavaScript function to do that:. For each folder to clear, just add another call to the clearFolder function.
This particular code also preserves exe and dll files, and cleans up subfolders as well. How about this modification on 7daysclean. The condition above contributed by J. And Month GEQ 2 is also wrong because adding seconds for one more day must be done in a leap year only for the months March to December, but not for February. A working code to take leap day into account - in current year only - in batch file 7daysclean.
Might I add a humble contribution to this already valuable thread. I don't know if it's a bug, but the CmdExec within the step only recognizes the first line of code:.
Gosh, a lot of answers already. In this example it works by picking all files. If you have the XP resource kit, you can use robocopy to move all the old directories into a single directory, then use rmdir to delete just that one:.
I think e. James's answer is good since it works with unmodified versions of Windows as early as Windows SP4 and possibly earlier , but it required writing to an external file. Log in Sign up. Search titles only. Search Advanced search…. New posts. Search forums. Log in. Sign up. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! JavaScript is disabled.
For a better experience, please enable JavaScript in your browser before proceeding. DOS Batch file to delete files by date range. Status This thread has been Locked and is not open to further replies. The original thread starter may use the Report button to request it be reopened but anyone else with a similar issue should start a New Thread. Watch our Welcome Guide to learn how to use this site. Show 2 more comments. Sign up or log in Sign up using Google. Sign up using Facebook.
Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. Podcast Making Agile work for data science. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually.
Related