instruct GAM to check for a top-level folder on a user's drive matching a string

270 views
Skip to first unread message

Kevan Chapman

unread,
Jun 20, 2024, 12:32:11 PM6/20/24
to GAM for Google Workspace
Hi All. 

New to GAM, still struggling with the basics. 

I have to circumstantially create a folder for a particular user, but want to first check for the existence of a folder with that name so I won't create a duplicate should circumstances repeat.
Foldernames to be added/checked for will be of the pattern "prefix-otherusername"

I've managed to get GAMADV-XTD3 to list top-level folders for me using

gam user cruiset.at.domain.ext print filetree showmimetype gfolder depth 0

but that also lists drive names at level -1. 

I *could* use a variant of this command, if I could just restrict the output to only the level-0 folders in "My Drive", without listing the drive name or any other drives and folders. I could pipe that restricted output to a list and check the list for a particular name before creating a duplicate folder.

However, I'd prefer to have a GAM command to directly query for the existance of a particular folder, say "test-dieselv" on cruiset's "My Drive" -- if the result is negative, I would create the folder; if it already exists, I would do nothing.

Thanks for any insights!

Kevan


Ross Scroggs

unread,
Jun 20, 2024, 12:40:56 PM6/20/24
to google-ap...@googlegroups.com

$ gam user testsimple show fileinfo query "'root' in parents and name = 'purgeme'" fields id

Getting all Drive Files/Folders that match query ('root' in parents and name = 'purgeme') for tests...@domain.com

Got 1 Drive File/Folder that matched query ('root' in parents and name = 'purgeme') for tests...@domain.com...

User: tests...@domain.com, Show 1 Drive File/Folder

  Drive Folder: purgeme (1kK0x4J9z-sPZnBTU-v2qvyFUTP0eSqlV)

    id: 1kK0x4J9z-sPZnBTU-v2qvyFUTP0eSqlV

$ echo $?

0


$ gam user testsimple show fileinfo query "'root' in parents and name = 'purgemex'" fields id

Getting all Drive Files/Folders that match query ('root' in parents and name = 'purgemex') for tests...@domain.com

Got 0 Drive Files/Folders that matched query ('root' in parents and name = 'purgemex') for tests...@domain.com...

User: tests...@domain.com, Show 0 Drive Files/Folders

$ echo $?

60



Substitute actual values for user name and folder name

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/25f518e3-506a-4e4c-8c68-be18a05d1053n%40googlegroups.com.

Kevan Chapman

unread,
Jun 20, 2024, 1:34:39 PM6/20/24
to GAM for Google Workspace
That's beautiful, Ross! Thanks so much!

Kevan

Kevan Chapman

unread,
Jun 20, 2024, 5:03:11 PM6/20/24
to GAM for Google Workspace
Follow-up question: Is there a way to suppress the display of the fields? i.e. just limit the per-folder output to:
 Drive Folder: purgeme (1kK0x4J9z-sPZnBTU-v2qvyFUTP0eSqlV)
From that one line I can get the name and the id, and I can have the query portion filter out trashed folders.

Ross Scroggs

unread,
Jun 20, 2024, 7:26:14 PM6/20/24
to google-ap...@googlegroups.com

$ gam config show_gettings false redirect csv - noheader user testsimple print filelist query "'root' in parents and name = 'purgeme'" fields id,name

tests...@domain.com,1kK0x4J9z-sPZnBTU-v2qvyFUTP0eSqlV,purgeme

$ echo $?

0

$ gam config show_gettings false redirect csv - noheader user testsimple print filelist query "'root' in parents and name = 'purgemex'" fields id,name

$ echo $?

60


Ross

----
Ross Scroggs


Chapman, Kevan

unread,
Jun 21, 2024, 9:34:43 AM6/21/24
to google-ap...@googlegroups.com
Thanks again Ross. Getting soooo close! Finally, how to limit the output to folders only? I've tried this query
"'root' in parents and mimetype=gfolder' (gives back invalid query)
and
"'root in parents and mimetype=application/vnd.google-apps.folder" (also  results in invalid query) 

Note: I *am* trying to figure this out from the documentation, but it seems this knowledge builds up holographically, and I'm not quite getting the picture yet...

Kevan

You received this message because you are subscribed to a topic in the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-manager/-MiANAd59-U/unsubscribe.
To unsubscribe from this group and all its topics, 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/AA259E70-B028-417D-8851-22B9BC99221E%40gmail.com.


--
Kevan Chapman
Technology Specialist
Pryor Public Schools Tech Team
'You never know until you find out!'

Ross Scroggs

unread,
Jun 21, 2024, 9:50:11 AM6/21/24
to google-ap...@googlegroups.com
"'root' in parents and name = 'purgeme'and mimeType = 'application/vnd.google-apps.folder'"
----
Ross Scroggs



Chapman, Kevan

unread,
Jun 21, 2024, 9:55:28 AM6/21/24
to google-ap...@googlegroups.com
Thanks! It was the single quotes that got me (again).

Reply all
Reply to author
Forward
0 new messages