Delete files older than X days on network share

This is more of a methodology question than a technical one. I am taking over and re-writing an old VB script for a customer. The customer uses a network share mapped to T:\ as a temporary space for users to drop files and folders internally, with the understanding that anything older than 2 days will automatically be deleted. There have been complaints for years from employees who would copy a file or folder out to this share only to find it gone the next day. In looking over the vbscript I see it is using the file object’s DateLastAccessed attribute to determine whether it is eligible for deletion.

I have found, however, a number of files that, when COPIED to the directory, retain all three of the original attributes (in PS parlance): CreationTime, LastWriteTime, and LastAccessTime so long as they are not opened (shortcuts for example). Others update the CreationTime when copied. I found as well that if a file is right click, dragged and MOVED to this temp directory none of these are updated, but they are if it is MOVED from the temp directory back to the local machine.

In essence, I’m just curious if anyone has dealt with this, or has any ideas. If I go with just last access time, I could be grabbing files that have only been in the temp directory for a short time (perhaps only minutes before the daily job runs) which is their current issue. My only thought is to grab all three attributes and check if any of them fall between the time the job last run and the current time, and try to deduce from there, but was hoping there was an easier way.

We use a similar “construct” for a temporary file share and we delete the content of this share every Saturday.

Do you mean you delete the entire directory? What if someone put something there on Friday they need until Monday? Is it just understood it will be gone?

Or do you mean you are checking all three attributes?

No. We really delete ALL content of the folder every Saturday. All Users know this. That’s how it is “designed”. At least its something the users can count on. If I got you right your users cannot be completely sure that the files they put there really stay for the 2 days. Our users can be sure everything they put there will stay there until Saturday. :wink: :smiley:

Thanks for clarifying. That is not what this customer is looking for.