Delete files but leave folders?

9 views
Skip to first unread message

Ian Crew

unread,
Jul 15, 2024, 3:01:25 PM (2 days ago) Jul 15
to google-ap...@googlegroups.com
Hi all:

Two related questions:

1) For a given myDrive folder (e.g. https://drive.google.com/drive/folders/0B07qASDFGHJKLL), how might I go about listing (first) and later deleting all files within that folder tree, leaving the folders intact?

2) For a given myDrive folder tree, how might I go about listing (first) and later deleting all items (files and folders) within that folder that are no longer shared with anyone?

I started to get into a command something like the following, but that seemed really complex, and requesting a whole lot of columns only to throw them away again with the csv_output_header_filter and csv_output_header_drop_filter commands, so maybe that's not the right way to do it?

gam config csv_output_header_filter "id,parents.0.id,permissions,path.0" csv_output_header_drop_filter "permissions." redirect csv - user ic...@berkeley.edu print filelist query "mimeType='application/vnd.google-apps.folder'" fullpath excludetrashed stripcrsfromname allfields

Thanks!

Ian

--
Ian Crew

Architect, Communication and Collaboration Services
Productivity & Collaboration Services
Berkeley IT
University of California, Berkeley

Ross Scroggs

unread,
Jul 15, 2024, 3:21:41 PM (2 days ago) Jul 15
to google-ap...@googlegroups.com
Ian,

1) Delete all files within a folder structure

gam redirect csv ./FolderFileList.csv user us...@domain.com print filelist select 0B07qASDFGHJKLL fields id,name,mimetype fullpath excludetrashed stripcrsfromname showmimetype not gfolder

gam redirect stdout ./DeleteFolderFiles.txt multiprocess redirect stderr stdout csv ./FolderFileList.csv gam user "~Owner" delete drivefile "~id"

#replace delete with purge to permanently delete file


2a) Delete all non-shared files within a folder structure

gam redirect csv ./FolderNonSharedFileList.csv user us...@domain.com print filelist select 0B07qASDFGHJKLL fields id,name,mimetype fullpath excludetrashed stripcrsfromname showmimetype not gfolder pm not role owner em pma skip

gam redirect stdout ./DeleteFolderNonSharedFiles.txt multiprocess redirect stderr stdout csv ./FolderNonSharedFileList.csv gam user "~Owner" delete drivefile "~id"

#replace delete with purge to permanently delete file


2b) Delete all non-shared folders within a folder structure

# This is tricky as a non-shared folder may have shared files within it.

# More thinking required.


Ross


----
Ross Scroggs



--
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/CAD2sLFvDYbbcuwvL%2B8BW7By0EaC6WSepmbvW3HYjUSAk5LrVtg%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages