Note: Leap seconds are not taken into account as the Windows file systems also do not support leap seconds.ĭays since 00:00:00 UTC for each year including leap days. So I decided to code the batch subroutine GetSeconds which calculates the number of seconds since 00:00:00 UTC for a date/time string passed to this routine. This very fast table method can be used also in batch code using FOR command. I use since 20 years static tables (arrays) created once with a small C function for quickly getting the number of days including leap days from in date/time conversion functions in my applications written in C/C . ![]() posted an add-on for taking leap day in current year into account, but ignoring the other leap years since base year, i.e. But it does not take leap years correct into account. Jay posted 7daysclean.cmd containing a fast "date to seconds" solution for command line interpreter cmd.exe. But any later day could be also used depending on the date range required to support for a specific task. 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.Ĭommon for operations based on date/time is the requirement to convert a date/time string to seconds since a determined day. But command line interpreter cmd.exe has no function for date/time calculations. There are very often relative date/time related questions to solve with batch file. 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).ĭid I mention I hate this editor's auto-formating? it removes the blank lines and the copy-paste is a hell. LIMITATIONĮpoch takes for granted your short date format is YYYY-MM-DD. if someone has an idea that would not add 10 lines of code, go ahead and post so I add it to my code.Įpoch: I did not take time into consideration, as the need is to delete files older than a certain date, taking hours/minutes would have deleted files from a day that was meant for keeping. ![]() Bissextile years is a hell to add, really. To something like : if !epoch! LEQ %slice% del /f %%fįebruary: is hard-coded to 28 days. This is non-destructive code, it will display what would have happened.Ĭhange : if !epoch! LEQ %slice% (echo DELETE %%f ^(%%~tf^)) ELSE echo keep %%f ^(%%~tf^) ![]() Set dSource=C:\temp : This is the starting directory to check for files. ![]() Set /a strip=day*7 : Change 7 for the number of days to keep. 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):įor /f "delims=" %%f in ('dir /a-d-h-s /b /s %dSource%') do (
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |