Gam script to create folders on team drive

948 views
Skip to first unread message

Rejaine Silveira Monteiro

unread,
Jun 14, 2021, 8:54:11 AM6/14/21
to google-ap...@googlegroups.com
Hi,

I created a team drive called TEAM1 and now I need to create a structure as follows:

FOLDER1
         A
         B
         C

FOLDER2
         A
         B
         C

FOLDER3
        .... SAME ABOVE UNTIL FOLDER40


I can create this structure using GAM ?

Esta mensagem pode conter informações confidenciais ou privilegiadas, sendo seu sigilo protegido por lei. Se você não for o destinatário ou a pessoa autorizada a receber esta mensagem, não pode usar, copiar ou divulgar as informações nela contidas ou tomar qualquer ação baseada nessas informações. Se você recebeu esta mensagem por engano, por favor avise imediatamente ao remetente, respondendo o e-mail e em seguida apague-o. Agradecemos sua cooperação.

Ross Scroggs

unread,
Jun 14, 2021, 9:30:20 AM6/14/21
to google-ap...@googlegroups.com
Rejaine,

This solution requires Advanced GAM.

Make a CSV file (TopFolders.csv) with one column: name
name
FOLDER1
FOLDER2
...
FOLDER40

Build top level folders
gam redirect stdout ./CreateTopFolders.txt multiprocess redirect stderr stdout csv TopFolders.csv gam user orga...@domain.com create drivefile drivefilename "~name" mimetype gfolder teamdriveparentid <PutTeamDriveIDHere>

Build second level folders
gam redirect stdout ./CreateSubFoldersA.txt multiprocess redirect stderr stdout csv TopFolders.csv gam user orga...@domain.com create drivefile drivefilename "A" mimetype gfolder teamdriveparentid <PutTeamDriveIDHere> teamdriveparentname "~name"
gam redirect stdout ./CreateSubFoldersB.txt multiprocess redirect stderr stdout csv TopFolders.csv gam user orga...@domain.com create drivefile drivefilename "B" mimetype gfolder teamdriveparentid <PutTeamDriveIDHere> teamdriveparentname "~name"
gam redirect stdout ./CreateSubFoldersC.txt multiprocess redirect stderr stdout csv TopFolders.csv gam user orga...@domain.com create drivefile drivefilename "C" mimetype gfolder teamdriveparentid <PutTeamDriveIDHere> teamdriveparentname "~name"

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/CAMTrDfWq87ZWVR_BWeEK8DY663sojz6uARrDv5Z1n1H5ST_g5A%40mail.gmail.com.

Rejaine Silveira Monteiro

unread,
Jun 14, 2021, 9:30:47 AM6/14/21
to google-ap...@googlegroups.com
Leave it, I found out here how to do it...

   gam user <user@mail> create drivefile drivefilename "FOLDERN" mimetype gfolder parentid <DRIVETEID>

Just create a script to use the command and everything was fine.

Peter Smulders

unread,
Jun 23, 2021, 5:36:42 AM6/23/21
to GAM for Google Workspace
I would like to add to the archive the remark that if you need to create folders in a very structured way, like in this example, it takes only a very small bit of looping in a script, rather than having to create a CSV by hand:

for A in {1..40}; do
  gam user us...@yourdomain.com create drivefile drivefilename "FOLDER${A}" mimetype gfolder teamdriveparentid <PutTeamDriveIDHere>
  for SUB in A B C; do
    gam us...@yourdomain.com create drivefile drivefilename "${SUB}" mimetype gfolder teamdriveparentid <PutTeamDriveIDHere> teamdriveparentname "FOLDER${A}"
  done
done

Now with the need for speed:

for A in {1..40}; do
  echo gam user us...@yourdomain.com create drivefile drivefilename "FOLDER${A}" mimetype gfolder teamdriveparentid <PutTeamDriveIDHere>
done | gam batch -
for A in {1..40}; do
  for SUB in A B C; do
    echo gam us...@yourdomain.com create drivefile drivefilename "${SUB}" mimetype gfolder teamdriveparentid <PutTeamDriveIDHere> teamdriveparentname "FOLDER${A}"
  done | gam batch -
done

If you are batching, do not mix or parallel run the loops, because the subfolders depend on the outer folders to exist first.

Turn up your num_threads to 25 or 30 and let 'er rip!

hth -- Peter

Bryan Clarke

unread,
Aug 8, 2022, 6:49:33 PM8/8/22
to GAM for Google Workspace
Hello, I know this is old but I keep coming across this as a method to solve what I need. I have an existing team drive with existing folder. I need to create 75 additional folders inside the existing shared folder on the team drive. I have created a TopFolders.csv and input my user and the folder id in the below line:
gam redirect stdout ./CreateTopFolders.txt multiprocess redirect stderr stdout csv TopFolders.csv gam user orga...@domain.com create drivefile drivefilename "~name" mimetype gfolder teamdriveparentid <PutTeamDriveIDHere>


this does not create the folders as expected. I am not sure what I am doing wrong. Can I get an assist, please?

Ross Scroggs

unread,
Aug 8, 2022, 6:52:34 PM8/8/22
to google-ap...@googlegroups.com
Bryan,

I replied to your earlier message asking you to send me A Meet/Zoom invitation but never heard from you; let's try again.

Send a Meet/Zoom request to ross.scroggs @ gmail.com

Ross

This message is intended only for the designated recipient(s).  This e-mail message and any documents attached to it are confidential and may contain information that is protected from disclosure by various federal and state laws, including the HIPAA privacy rule (45 C.F.R., Part 164).  If you are not the intended recipient, be advised that any use, dissemination, forwarding, printing, or copying of this message without the sender's written permission is strictly prohibited and may be unlawful.  Accordingly, if you have received this message in error, please notify the sender immediately by return e-mail or call (512) 628-0465, and then delete this message.

--
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.


--
Reply all
Reply to author
Forward
0 new messages