Want a script to delete files that are older than a certain date? Lets say more then 30 days old.
Your mind first races to the created date stamp. Well you may need to think that over in some situations!
Lets take a look at some date stamps in Windows. Then I’ll explain.
This file was last modified over a month before it was created !!!!
No its not photoshop or dark sysadmin scripting or even magic computer time travel!
Its actually a lot simpler than that. Simply it was copied. But it does put you in a peculiar situation.
When do we consider the file to be created? The moment it was conceived or the moment it arrived on this disk. Here’s an even better mind twister.
Consider that you have a script that copies files from file shares to a central repository and then deletes files older than say 30 days. Well the files would be greater than 30 days old before they get deleted. Since the dates created date would be the date that the file was copied to the disk. This is if you only copy the file once.
There is no simple solution to this one, but its worth keeping in mind the next time that you want to write a script.
I sometimes like to make use of time stamps in the names. These should never change in automated systems.