Shared TempDrive Cleanup Script – Automated

Sometimes it’s not possible to remember a specific weekly job to perform. So if we can make it as scheduled job to do the same, it will be better. There will be not such risk. Just take my example, I have to clean our office common shared temporary folder on every Sunday, but I am not in office on Sunday. So, I have two options to do the same, first, I have to call our DCO Support and instruct them to get the job done, and if I go with this option there will be lots of dependencies, or else I have to create a script which will do the job automatically.


So I decided to go for second option. With second option I have to make sure following things should be perform.

  • I just can’t delete all files & folder from temp drive, coz there might came some requirement to recover files from last week temp drive(Yes, everyone aware of the temp drive policy). So, I have to copy all the content of the Temp Drive to a different location.
  • I have to create a folder with date stamp, eg. Folder_date (tempbkp_23-09-2009). So, I have to create a specific date variable.
  • After copy all content of the temp drive to other location, I have to give Everyone Read only permission to that folder and then have to share that folder as well.
  • Delete all files and folder from temp drive. Yea, as per my knowledge, there is no such command available on windows by which I can delete all files and folder from a specific folder or a specific map drive. (So…..time to think some alternatives)
  • Now the critical part, on next scheduled date, this script will automatically delete last backup folder, and create a new folder for latest backup.

And finally I made it with considering all above requirement without using any third part toolsJ. And as of now it’s working properly, check out the script bellow.

 

Leave a Reply

Your email address will not be published. Required fields are marked *