Deleting Shared Drive Files and Folders

617 views
Skip to first unread message

Linux_01

unread,
Jan 4, 2022, 3:53:59 AM1/4/22
to GAM for Google Workspace
Hello Team,

I want to delete files and folders of a Specific Shared Drive whose files and folders are 6 months old using Gam command.

How can I achieve it ?

Thank you.

Ross Scroggs

unread,
Jan 4, 2022, 11:20:11 AM1/4/22
to google-ap...@googlegroups.com
Be careful here, you delete a folder and everything in it goes.
Try this to get all files not modified in the last 180 days.
gam redirect ./OldSharedDriveFiles.csv user orga...@domain.com print filelist select teamdriveid 1245LiIe4dqxZUk9789 showmimetype not gfolder querytime180days -180d query "modifiedTime<'#querytime180days#'" fields id,name,mimetype,modifiedTime

Inspect OldSharedDriveFiles.csv and make sure it`s what you want, proceed if you're sure of what you're doing.
gam redirect stdout ./DeleteOldSharedDriveFiles.txt multiprocess redirect stderr stdout csv ./OldSharedDriveFiles.csv gam user "~Owner" delete drivefile "~id"

Ross

--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/4141b3fa-3d05-415d-a15b-58c45c3e6004n%40googlegroups.com.

Message has been deleted

Ross Scroggs

unread,
Apr 29, 2022, 9:30:56 AM4/29/22
to google-ap...@googlegroups.com
Jason,

My mistake, csv keyword omitted.

gam redirect csv ./OldSharedDriveFiles.csv user orga...@domain.com print filelist select teamdriveid 1245LiIe4dqxZUk9789 showmimetype not gfolder querytime180days -180d query "modifiedTime<'#querytime180days#'" fields id,name,mimetype,modifiedTime

Ross


On Apr 29, 2022, at 5:26 AM, Jason Komendat <jkom...@crschools.us> wrote:

Ross when I try this I am getting this error

ERROR: Invalid choice (./oldshareddrivefiles.csv): Expected <csv|stdout|stderr>

Jason Komendat

unread,
Apr 29, 2022, 10:06:07 AM4/29/22
to GAM for Google Workspace
Sorry I had tried to hit delete comment I found that, but quick quesrtin is there a way to for example move the files to another location vs delete

SO instead of this
gam redirect stdout ./DeleteOldSharedDriveFiles.txt multiprocess redirect stderr stdout csv ./OldSharedDriveFiles.csv gam user "~Owner" delete drivefile "~id"

Something like  gam redirect stdout ./DeleteOldSharedDriveFiles.txt multiprocess redirect stderr stdout csv ./OldSharedDriveFiles.csv gam user "~Owner" SYNTAX to move thise files?

Ross Scroggs

unread,
Apr 29, 2022, 10:12:47 AM4/29/22
to google-ap...@googlegroups.com
Jason,

Yes you can move files but more details are required.
Do you want ot move files and folders?
Do you want to move them to another location on the same Shared Drive or a different Shared Drive?

Jason Komendat

unread,
Apr 29, 2022, 10:16:45 AM4/29/22
to GAM for Google Workspace
Awesome, we'd probably just want to move files not folders and for this to another shared drive.  The scenerio is we're looking at some data retention actions. So for example a shared drive that maybe we set a task to move all files out that are over 3 years etc. I know we can delete them but the managers just wants them moved to another "review' folder so the managers can review them before they are deleted (yes I know they never will but still) So I'm trying to cobble together the commands to do something like that if possible. 

Jason Komendat

unread,
Apr 29, 2022, 10:35:06 AM4/29/22
to GAM for Google Workspace
And now a new strange issue. This below command worked before to make the "list" CSV of OldSharedDriveFiles.csv but its not anymore. Is there some cache file that needs to be purged between runs of this command/


gam redirect csv OldSharedDriveFiles.csv user ME@OURDOMAIN print filelist select teamdriveid 0AJOVvV-4VxnpUk9PVA showmimetype not gfolder querytime180days -180d query "modifiedTime<'#querytime180days#'" fields id,name,mimetype,modifiedTime


PS C:\Users\dpool\Documents> gam redirect csv OldSharedDriveFiles.csv user  ME@OURDOMAIN   print filelist select
teamdriveid 0AJOVvV-4VxnpUk9PVA showmimetype not gfolder querytime180days -180d query "modifiedTime<'#querytime180days#'
" fields id,name,mimetype,modifiedTime
Getting all Drive Files/Folders that match query ((modifiedTime<'2021-10-31T00:00:00-05:00') and (mimeType != 'applicati
on/vnd.google-apps.folder')) for  ME@OURDOMAIN
Got 57 Drive Files/Folders that matched query ((modifiedTime<'2021-10-31T00:00:00-05:00') and (mimeType != 'application/
vnd.google-apps.folder')) for  ME@OURDOMAIN  ...
PS C:\Users\dpool\Documents>

Ross Scroggs

unread,
Apr 29, 2022, 10:54:10 AM4/29/22
to google-ap...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages