Whenever you share a Google Drive folder, the sharing is always permanent. That means till you manually change or remove the sharing, people with whom the folder is shared will be able to access it.

But sometimes you want to share a folder only for a specific time. That means you want to share a folder in your Google drive and have the sharing automatically expire or disable at a specific date and time. Google doesn't have such a functionality inbuilt, but is possible to do with a small trick.

Disable folder sharing in Google Drive after expiry date.

Setting an expiry date for a shared Google Drive folder is done with a small script. Here's how to use it -

  1. First open this Google Script and then select File->Make a copy. This will copy the script to your Google Drive.
  2. Now change to values of FOLDER_URL and EXPIRY_TIME at the top of the script to your shared folder url and the time you want the sharing to expire. Please note the the time should be in YYYY-MM-DD HH:MM format.
  3. Select Run->Initialize and grant the permissions required.
  4. Select Run->Start.

That's it. A trigger will get created which will automatically expire the shared links at the time you specified. Not only that, it will also send you an email confirmation after the sharing is disabled.

How it works!

The script internally creates a trigger to run at the time you specified. The trigger creates a copy of your shared folder, deletes the original folder and renames the copy to the name of the original. Once you delete the original folder, everything including the shared links become obsolete. The copy is just like a new folder and won't be shared with anybody.