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.


Disclaimer: All posts and opinions on this site are provided AS IS with no warranties. These are our own personal opinions and do not represent our employer’s view in any way.

This article currently have 5,793 views

Follow me

CC BY-ND 4.0 This work is licensed under a Creative Commons Attribution-NoDerivatives 4.0 International License.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.