create a copy of non-movable files

61 views
Skip to first unread message

Tobias Aicher

unread,
Nov 29, 2022, 11:07:05 AM11/29/22
to GAM for Google Workspace
Hi everyone,

I have a short question regarding gam and google drive.
I try to clean up some shares and move the files & folders to a shareddrive for archiving.
Unfortunately the shares are located in the mydrives of several users, so I can't claim the ownership of files, from external user.

As we don't want to lose the history of the files, we want to move everything instead of a simple copy, where possible.

My actual question now is, is there a way to move everything and copy non-movable files and also keep the folder structure.

The move option only allows to create a shortcut or do nothing.
I also tried to copy everything first and overwrite with a move on a second run, but than the copies of the non-movable files will be deleted.

Thanks in advance.




Tobias Aicher

unread,
Dec 5, 2022, 3:11:07 AM12/5/22
to GAM for Google Workspace
just wanted to post the solution Ross and I came up after our debuggin session

The problem is, that even as it looks like a folderstructure like on any other os, it's not. And even that you know this fact you sometimes forget it works in a different way

so the sollution for this problem was simple, change the order of the commands. You first need to move all files and than create the copy.

It then moves all files it can move and also creates the folder structure, after that you simply copy all the remaining files you are not the owner. You don't have to worry about duplicates, as there are none.

here are my two commands:

## 1st - MOVE ##

gam user <user_email> \
    move drivefile <source_file_ID> \
    newfilename "<DriveFileName> \
    teamdriveparentid <target_shareddrive_ID> \
    duplicatefiles overwriteall \
    createshortcutsfornonmovablefiles false \
    mergewithparentretain false \
    duplicatefolders merge \
    copymergedtopfolderpermissions false \
    copymergedsubfolderpermissions false \
    copytopfoldernoninheritedpermissions never \
    copysubfoldernoninheritedpermissions never \
    retainsourcefolders true \
    summary

## 2nd - COPY ##

gam user <user_email> \
    copy drivefile <source_file_ID> \
    teamdriveparentid <target_shareddrive_ID> \
    teamdriveparentname <DriveFileName> \ # the newfilename you set in the move command
    mergewithparent true \
    recursive \
    duplicatefolders merge \
    copyfilepermissions false \
    copymergewithparentfolderpermissions false \
    copymergedsubfolderpermissions false \
    copytopfolderinheritedpermissions false \
    copysubfolderinheritedpermissions false \
    copytopfoldernoninheritedpermissions never \
    copysubfoldernoninheritedpermissions never \
    summary


FYI
In my initial question, I mentioned that the copies of my non-moveable files disapear in during the move command. We also looked into this behavior and they definitely were deleted during this run. Ross will have a look into this, as the files should not have been deleted, but the propper solution is the one above.

@Ross many thanks again for your time, it was a fun debugging sessaion!

Many thanks,
Tobias

David Lee

unread,
Feb 13, 2024, 5:49:35 AMFeb 13
to GAM for Google Workspace
Just to say that I found this very useful today. Worked exactly as I needed it to. Thanks for sharing.

My next mission is to find something that will rename the original files that were COPIED to include a 'DO NOT USE - DELETE'  at the beginning and also try and delete. Just to help people that may discover these redundant files at a later date. I feel this last bit completes this and will post back if I manage to find the answer.

Many thanks,

David.
Reply all
Reply to author
Forward
0 new messages