1
2
We have a network folder used as a holding area for XML files that were not properly processed. I’ve been asked to design a script that runs every five minutes and checks the folder for any files less than five minutes old. If it finds files less than five minutes old, it moves them into another directory to be processed.
The trick is, we only want it to move the files one time. If they fail a second time, they will be thrown back into that folder and need to remain there to be dealt with later.
The file names each contain a unique time and date stamp as part of the file name. It’s a little convoluted, but the format is:
YYYYMMDDHHmmSSSSS
I was thinking there might be a way for PowerShell to look at the “mm” stamp of the filename and compare it to the current time. If it’s less than five minutes old, it moves it. If it’s greater than five minutes old, it leaves it alone.
Is this possible?
Obtain the filename as a string, look at index 10-11 and compare them. A less error prone approach would be to convert the timestamps to the absolute time of the unix epoch (seconds since 1. jan 1970) and do comparisons by subtracting 300. I wish I had a windows box at hand to give you a more concrete example, but this is certainly possible. – Ярослав Рахматуллин – 2012-10-26T19:53:02.480