# Users - Drive Files Display
- [API documentation](#api-documentation)
- [Query documentation](Users-Drive-Query)
- [Python Regular Expressions](Python-Regular-Expressions) Match function
- [Permission Matches](Permission-Matches)
- [Definitions](#definitions)
- [Return Codes](#return-codes)
- [Display file information](#display-file-information)
- [Display file paths](#display-file-paths)
- [Select files for Display file counts, list, tree](#select-files-for-display-file-counts-list-tree)
  - [File selection definitions](#file-selection-definitions)
  - [File selection defaults](#file-selection-defaults)
  - [File selection by query](#file-selection-by-query)
  - [File selection of Shared Drive](#file-selection-of-shared-drive)
  - [File selection by corpora](#file-selection-by-corpora)
  - [File selection by ownership](#file-selection-by-ownership)
  - [File selection by MIME type](#file-selection-by-mime-type)
  - [File selection by file size](#file-selection-by-file-size)
  - [File selection by file name pattern matching](#file-selection-by-file-name-pattern-matching)
  - [File selection by permission matching](#file-selection-by-permission-matching)
  - [File selection to exclude items in the trash](#file-selection-to-exclude-items-in-the-trash)
- [Display file counts](#display-file-counts)
- [Display file share counts](#display-file-share-counts)
- [Display file tree](#display-file-tree)
  - [File selection starting point for Display file tree](#file-selection-starting-point-for-display-file-tree)
- [Display file list](#display-file-list)
  - [File selection by name and entity shortcuts for Display file list](#file-selection-by-name-and-entity-shortcuts-for-display-file-list)
  - [File selection starting point for Display file list](#file-selection-starting-point-for-display-file-list)
  - [File selection with a particular drive label](#file-selection-with-a-particular-drive-label)
  - [Handle empty file lists](#handle-empty-file-lists)
- [Display disk usage](#display-disk-usage)

## API documentation
* https://developers.google.com/drive/api/v3/reference/files

## Definitions
* [`<DriveFileEntity>`](Drive-File-Selection)
* [`<UserTypeEntity>`](Collections-of-Users)

```
<CorporaAttribute> ::=
        alldrives |
        domain |
        onlyteamdrives |
        user
<DomainName> ::= <String>(.<String>)+
<EmailAddress> ::= <String>@<DomainName>
<UniqueID> ::= id:<String>
<Time> ::=
        <Year>-<Month>-<Day>(<Space>|T)<Hour>:<Minute>:<Second>[.<MilliSeconds>](Z|(+|-(<Hour>:<Minute>))) |
        (+|-)<Number>(m|h|d|w|y) |
        never|
        now|today

<MimeTypeShortcut> ::=
        gdoc|gdocument|
        gdrawing|
        gfile|
        gfolder|gdirectory|
        gform|
        gfusion|
        gmap|
        gpresentation|
        gscript|
        gsheet|gspreadsheet|
        gshortcut|
        g3pshortcut|
        gsite
<MimeTypeName> ::= application|audio|font|image|message|model|multipart|text|video
<MimeType> ::= <MimeTypeShortcut>|(<MimeTypeName>/<String>)
<MimeTypeList> ::= "<MimeType>(,<MimeType>)*"
```
```
<DriveCapabilitiesSubfieldName> ::=
        canacceptownership|
        canaddchildren|
        canaddfolderfromanotherdrive|
        canaddmydriveparent|
        canchangecopyrequireswriterpermission|
        canchangedomainusersonlyrestriction|
        canchangedrivebackground|
        canchangedrivemembersonlyrestriction|
        canchangesecurityupdateenabled|
        canchangesharingfoldersrequiresorganizerpermissionrestriction|
        canchangeviewerscancopycontent|
        cancomment|
        cancopy|
        candelete|
        candeletechildren|
        candeletedrive|
        candownload|
        canedit|
        canlistchildren|
        canmanagemembers|
        canmodifycontent|
        canmodifycontentrestriction|
        canmodifylabels|
        canmovechildrenoutofdrive|
        canmovechildrenoutofteamdrive|
        canmovechildrenwithindrive|
        canmovechildrenwithinteamdrive|
        canmoveitemintoteamdrive|
        canmoveitemoutofdrive|
        canmoveitemoutofteamdrive|
        canmoveitemwithindrive|
        canmoveitemwithinteamdrive|
        canmoveteamdriveitem|
        canreaddrive|
        canreadlabels|
        canreadrevisions|
        canreadteamdrive|
        canremovechildren|
        canremovemydriveparent|
        canrename|
        canrenamedrive|
        canresetdriverestrictions|
        canshare|
        cantrash|
        cantrashchildren|
        canuntrash

<DriveContentRestrictionsSubfieldName> ::=
        ownerrestricted|
        readonly|
        reason|
        restrictinguser|
        restrictiontime|
        type

<DriveLabelInfoSubfieldName> ::=
        labels.id|              # modifiedByMe
        labels.revisionid|      # copyRequiresWriterPermission
        labels.fields           # viewedByMe

<DriveLabelsSubfieldName> ::=
        labels.modified|        # modifiedByMe
        labels.restricted|      # copyRequiresWriterPermission
        labels.starred|         # starred
        labels.trashed|         # trashed
        labels.viewed           # viewedByMe

<DriveOwnersSubfieldName> ::=
        owners.displayname|
        owners.emailaddress|
        owners.isauthenticateduser|
        owners.me|
        owners.permissionid|
        owners.photolink|
        owners.picture

<DriveParentsSubfieldName> ::=
        parents.id|
        parents.isroot

<DrivePermissionsSubfieldName> ::=
        permissions.additionalroles|
        permissions.allowfilediscovery|
        permissions.deleted|
        permissions.permissiondetails|
        permissions.displayname|
        permissions.domain|
        permissions.emailaddress|
        permissions.expirationdate|
        permissions.expirationtime|
        permissions.id|
        permissions.name|
        permissions.photolink|
        permissions.role|
        permissions.type|
        permissions.withlink

<DriveLastModifyingUserSubfieldName> ::=
        lastmodifyinguser.displayname|
        lastmodifyinguser.emailaddress|
        lastmodifyinguser.isauthenticateduser|
        lastmodifyinguser.me|
        lastmodifyinguser.name|
        lastmodifyinguser.permissionid|
        lastmodifyinguser.photolink|
        lastmodifyinguser.picture

<DriveSharingUserSubfieldName> ::=
        sharinguser.displayname|
        sharinguser.emailaddress|
        sharinguser.isauthenticateduser|
        sharinguser.me|
        sharinguser.name|
        sharinguser.permissionid|
        sharinguser.photolink|
        sharinguser.picture

<DriveTrashingUserSubfieldName> ::=
        trashinguser.displayname|
        trashinguser.emailaddress|
        trashinguser.isauthenticateduser|
        trashinguser.me|
        trashinguser.name|
        trashinguser.permissionid|
        trashinguser.photolink|
        trashinguser.picture

<DriveShortcutDetailsSubfieldName> ::=
        shortcutdetails.targetid|
        shortcutdetails.targetmimetype
        shortcutdetails.resourcekey
```
```
<DriveFieldName> ::=
        alternatelink|
        appdatacontents|
        appproperties|
        basicpermissions|
        cancomment|
        canreadrevisions|
        capabilities|
        <DriveCapabilitiesSubfieldName>|
        contenthints|
        contentrestrictions|
        <DriveContentRestrictionsSubfieldName>|
        copyable|
        copyrequireswriterpermission|
        createddate|createdtime|
        description|
        driveid|
        drivename|
        editable|
        explicitlytrashed|
        exportlinks|
        fileextension|
        filesize|
        foldercolorrgb|
        fullfileextension|
        hasaugmentedpermissions|
        hasthumbnail|
        headrevisionid|
        iconlink|
        id|
        imagemediametadata|
        isappauthorized|
        labelinfo|
        <DriveLabelInfoSubfieldName>|
        labels|
        <DriveLabelsSubfieldName>|
        lastmodifyinguser|
        <DriveLastModifyingUserSubfieldName>|
        lastmodifyingusername|
        lastviewedbyme|lastviewedbymedate|lastviewedbymetime|lastviewedbyuser|
        linksharemetadata|
        md5|md5checksum|md5sum|
        mime|mimetype|
        modifiedbyme|modifiedbymedate|modifiedbymetime|modifiedbyuser|
        modifieddate|modifiedtime|
        name|
        originalfilename|
        ownedbyme|
        ownernames|
        owners|
        <DriveOwnersSubfieldName>|
        parents|
        <DriveParentsSubfieldName>|
        permissions|
        <DrivePermissionsSubfieldName>|
        permissionids|
        properties|
        quotabytesused|quotaused|
        resourcekey|
        restricted|
        shareable|
        shared|
        sharedwithmedate|sharedwithmetime|
        sharinguser|
        <DriveSharingUserSubfieldName>|
        shortcutdetails|
        <DriveShortcutDetailsSubfieldName>|
        size|
        spaces|
        starred|
        teamdriveid|
        teamdrivename|
        thumbnaillink|
        thumbnailversion|
        title|
        trashed|
        trasheddate|trashedtime|
        trashinguser|
        <DriveTrashingUserSubfieldName>|
        userpermission|
        version|
        videomediametadata|
        viewed|
        viewedbymedate|viewedbymetime|
        viewerscancopycontent|
        webcontentlink|
        webviewlink|
        writerscanshare
<DriveFieldNameList> ::= "<DriveFieldName>(,<DriveFieldName>)*"
```
`basicpermissions` is equivalent to:
```
permissions.allowFileDiscovery,
permissions.deleted,
permissions.domain,
permissions.emailAddress,
permissions.expirationTime,
permissions.id,
permissions.role,
permissions.type
```
In particular, this omits these fields:
```
permissions.displayName,
permissions.permissionDetails,
permissions.photoLink,
permissions.teamDrivePermissionDetails
```
This allows you to select the essential permission fields without enumerating them. Of course,
you can specify `permissions` to get all of the fields, enumerate the specific fields you want or
specify `basicpermissions` and additional permission fields, e.g., `permissions.displayName`.

```
<<DriveOrderByFieldName> ::=
        createddate|createdtime|
        folder|
        modifiedbyme|modifiedbymedate|modifiedbymetime|modifiedbyuser|
        modifieddate|modifiedtime|
        name|
        name_natural|
        quotabytesused|quotaused|
        recency|
        sharedwithmedate|sharedwithmetime|
        starred|
        title|
        title_natural|
        viewedbymedate|viewedbymetime
```
## Return Codes
When a command involves a query:
* If any files match the query, a return code of 0 is returned.
* If no files match the query, a return code of 60 is returned.

### Examples
You want to test for the existance of a Google drive folder:
```
$ gam user user1@domain.com show fileinfo query "name = 'Top Folder' and mimeType ='application/vnd.google-apps.folder'" id
Getting all Drive Files/Folders that match query (name = 'Top Folder' and mimeType ='application/vnd.google-apps.folder') for user1@domain.com
Got 1 Drive File/Folder that matched query (name = 'Top Folder' and mimeType ='application/vnd.google-apps.folder') for user1@domain.com...
User: user1@domain.com, Show 1 Drive File/Folder
  Drive Folder: Top Folder (1kdHaDm2XOmGKVsyBgPBugWqdE3xTwxyz)
    id: 1kdHaDm2XOmGKVsyBgPBugWqdE3xTwxyz
$ echo $?
0
$ gam user user2@domain.com show fileinfo query "name = 'Top Folder' and mimeType ='application/vnd.google-apps.folder'" id
Getting all Drive Files/Folders that match query (name = 'Top Folder' and mimeType ='application/vnd.google-apps.folder') for user2@domain.com
Got 0 Drive Files/Folders that matched query (name = 'Top Folder' and mimeType ='application/vnd.google-apps.folder') for user2@domain.com...
User: user2@domain.com, Show 0 Drive Files/Folders
$ echo $?
60
```

## Display file information
Display file details in indented keyword: value format. The two forms are equivalent.
```
gam <UserTypeEntity> show fileinfo <DriveFileEntity>
        [returnidonly]
        [filepath|fullpath] [pathdelimiter <Character>]
        [allfields|<DriveFieldName>*|(fields <DriveFieldNameList>)]
        (orderby <DriveFileOrderByFieldName> [ascending|descending])*
        [showdrivename] [showshareddrivepermissions]
        [(showlabels details|ids)|(includelabels <DriveLabelIDList>)]
        [showparentsidsaslist]
        [stripcrsfromname]
        [formatjson]
gam <UserTypeEntity> info drivefile <DriveFileEntity>
        [returnidonly]
        [filepath|fullpath] [pathdelimiter <Character>]
        [allfields|<DriveFieldName>*|(fields <DriveFieldNameList>)]
        (orderby <DriveFileOrderByFieldName> [ascending|descending])*
        [showdrivename] [showshareddrivepermissions]
        [(showlabels details|ids)|(includelabels <DriveLabelIDList>)]
        [showparentsidsaslist]
        [stripcrsfromname]
        [formatjson]
```
Use `returnidonly` to display just the file ID of the files in `<DriveFileEntity>`.

Use `filepath` to display the path(s) to the files in `<DriveFileEntity>`.

Use `fullpath` to add additional path information indicating that a file is an Orphan or Shared with me.

By default, file path components are separated by `/`; use `pathdelimiter <Character>` to use `<Character>` as the separator.

When `allfields` is specified (or no fields are specified), use `showdrivename` to display Shared(Team) Drive names.
An additional API call is required to get each Shared(Team) Drive name; the names are cached so there is only one additional
API call per Shared(Team) Drive.

When `allfields` is specified (or no fields are specified), use `showshareddrivepermissions` to display permissions
for `<DriveFileEntity>` when it is a shared drive file/folder. In this case, the Drive API returns the permission IDs
but not the permissions themselves so GAM makes an additional API call to get the permissions.

By default, when file parents are displayed, they are displayed in this form:
```
  parents:
    id: <DriveFileID>
      isRoot: <Boolean>
    id: <DriveFileID>
      isRoot: <Boolean>
    ...
```
The `showparentsidsaslist` option changes the output to this form:
```
  parentsIds: <DriveFileID> <DriveFileID> ...
```
There is no `isRoot` information displayed.

By default, no Drive Label information is displayed. Use the following options to display this information;
an API call per file is required to get the information.
* `showlabels details`
```
  labels:
    id: <DriveLabelID>
      revisionId: <Number>
    id: <DriveLabelID>
      revisionId: <Number>
```
* `showlabels ids`
```
  labelsIds: <DriveLabelID> <DriveLabelID> ...
```

Starting in version 6.27.02, you can get Drive label information without an extra API call
if you know the `<DriveLabelID>`s. Add `labelinfo` to your `fields` list and use `includelabels <DriveLabelIDList>`
to specify the Drive labels.
```
gam user user@domain.com show fileinfo <DriveFileEntity> fields id,name,mimetype,labelinfo includelabels "mRoha85IbwCRl490E00xGLvBsSbkwIiuZ6PRNNEbbFcb"
```

The `stripcrsfromname` option strips nulls, carriage returns and linefeeds from drive file names.
Use this option if you discover filenames containing these special characters; it is not common.

By default, Gam displays the information as an indented list of keys and values.
* `formatjson` - Display the fields in JSON format.

## Display file paths
```
gam <UserTypeEntity> show filepath <DriveFileEntity>
        [returnpathonly]
        (orderby <DriveFileOrderByFieldName> [ascending|descending])*
        [stripcrsfromname] [fullpath] [pathdelimiter <Character>]
gam <UserTypeEntity> print filepath <DriveFileEntity> [todrive <ToDriveAttribute>*]
        (orderby <DriveFileOrderByFieldName> [ascending|descending])*
        [stripcrsfromname] [fullpath] [pathdelimiter <Character>]
        [oneitemperrow]
```
Use `returnpathonly` to display just the file path of the files in `<DriveFileEntity>`.

Use `fullpath` to add additional path information indicating that a file is an Orphan or Shared with me.

By default, file path components are separated by `/`; use `pathdelimiter <Character>` to use `<Character>` as the separator.

The `stripcrsfromname` option strips nulls, carriage returns and linefeeds from drive file names.
Use this option if you discover filenames containing these special characters; it is not common.

By default, when printing file paths, all paths for a file are displayed on the same row; use `oneitemperrow` to
have each file path displayed on a separate row.

## Select files for Display file counts, list, tree
Most GAM commands that deal with files require a `<DriveFileEntity>` to be specified; the command
then processes those files. The `filecounts`, `filelist` and `filetree` commands don't process files, they just list them.
They offer more powerful methods to select the files to be displayed.

## File selection definitions
See: [Drive File Selection](Drive-File-Selection) for details of `<DriveFileNameEntity>`, `<DriveFileQueryShortcut>` and `<DriveFileEntity>`.
```
<DriveFileNameEntity> ::=
        (anyname <DriveFileName>) | (anyname:<DriveFileName>) |
        (anydrivefilename <DriveFileName>) | (anydrivefilename:<DriveFileName>) |
        (name <DriveFileName>) | (name:<DriveFileName>) |
        (drivefilename <DriveFileName>) | (drivefilename:<DriveFileName>) |
        (othername <DriveFileName>) | (othername:<DriveFileName>) |
        (otherdrivefilename <DriveFileName>) | (otherdrivefilename:<DriveFileName>)

<DriveFileQueryShortcut> ::=
        all_files |
        all_folders |
        all_google_files |
        all_non_google_files |
        all_shortcuts |
        all_3p_shortcuts |
        all_items |
        my_files |
        my_folders |
        my_google_files |
        my_non_google_files |
        my_shortcuts |
        my_3p_shortcuts |
        my_items |
        others_files |
        others_folders |
        others_google_files |
        others_non_google_files |
        others_shortcuts |
        others_3p_shortcuts |
        others_items |
        writable_files

<DriveFileEntity> ::=
        <DriveFileIDEntity> |
        <DriveFileNameEntity> |
        <DriveFileQueryEntity> |
        <DriveFileQueryShortcut> |
        root|mydrive |
        <SharedDriveIDEntity> [<SharedDriveFileQueryShortcut>] |
        <SharedDriveNameEntity> [<SharedDriveFileQueryShortcut>] |
        <SharedDriveFileNameEntity> |
        <SharedDriveFileQueryEntity> |
        <FileSelector> | <CSVFileSelector> | <CSVkmdSelector> | <CSVSubkeySelector>) | <CSVDataSelector>)
```

## File selection defaults
By default, file selection starts with a query of "'me' in owners".
The sections below detail other methiods for selecting files.

## File selection by query
Select a subset of files by query.

This option is not available for `print|show filetree`.
```
((query <QueryDriveFile>) | (fullquery <QueryDriveFile>) | <DriveFileQueryShortcut>) (querytime<String> <Time>)*
```
* `query "xxx"` - ` and xxx` is appended to the current query; you can repeat the query argument to build up a longer query.
* `fullquery "xxx"` - The query is set to `xxx` eliminating the initial `'me' in owners`.
* `<DriveFileQueryShortcut>` - Predefined queries

Use the `querytime<String> <Time>` option to allow times, usually relative, to be substituted into the `query <QueryDriveFile>` option.
The `querytime<String> <Time>` value replaces the string `#querytime<String>#` in any queries.
The characters following `querytime` can be any combination of lowercase letters and numbers. This is most useful in scripts
where you can specify a relative date without having to change the script.

For example, query for files last modified me than 5 years ago:
```
querytime5years -5y query "modifiedTime<'#querytime5years#'"
```

## File selection of Shared Drive
You can limit the selection for files on a specific Shared drive.
Any query will be applied to the Shared drive.
```
select <SharedDriveEntity>
```
## File selection by corpora
Select files by corpora.

This option is not available for `print|show filetree`.
```
corpora <CorporaAttribute>
```
* `corpora alldrives` - Selects files on Shared Drives and files owned by or shared to the user.
* `corpora domain` - Selects files shared to the user's domain.
* `corpora onlyteamdrives` - Selects files on Shared Drives.
* `corpora user` - Selects files owned by or shared to the user.

## File selection by ownership
By default, files owned by the user are selected. These options update the current query with the desired ownership.
```
anyowner|(showownedby any|me|others)

```
* `showownedby me` - Select files owned by the user; this is the default
* `showownedby any` or `anyowner` - Select files accessible by the user
* `showownedby others` - Select files not owned by the user

## File selection by MIME type
By default, all types of files and folders are selected. You can specify a list of MIME types to display or a list of MIME types to suppress.
This option updates the current query.
```
showmimetype [not] <MimeTypeList>
```
* `showmimetype <MimeTypeList>` - Select files and folders with the specified MIME types
* `showmimetype not <MimeTypeList>` - Select files and folders with MIME types other than those specified

## File selection by file size
These options would typically be used with `showmimetype` to select files of a particular type. This
selection is performed by GAM, not the API.

* `minimumfilesize <Integer>` - Limit the selection to files with content of size >= `<Integer>`
* `maximumfilesize <Integer>` - Limit the selection to files with content of size <= `<Integer>`

## File selection by file name pattern matching
This option allows you to limit the display to files whose name matches `<RegularExpression>`.
The Drive API supports basic file name selection via query; this selection by pattern matching
is performed by GAM. You could use a query to do broad file name matching and then fine tune it with
`filenamematchpattern`.
```
filenamematchpattern <RegularExpression>
```

## File selection by permission matching
See: [Permission Matches](Permission-Matches)

## File selection to exclude items in the trash
This option excludes items in the trash from being selected.
```
excludetrashed
```

## Display file counts
Print or show file counts by MIME type and/or file name.
```
gam <UserTypeEntity> print filecounts [todrive <ToDriveAttribute>*]
        [((query <QueryDriveFile>) | (fullquery <QueryDriveFile>) | <DriveFileQueryShortcut>)
            (querytime<String> <Time>)*]
        [corpora <CorporaAttribute>]
        [select <SharedDriveEntity>]
        [anyowner|(showownedby any|me|others)]
        [showmimetype [not] <MimeTypeList>] [minimumfilesize <Integer>] [maximumfilesize <Integer>]
        [filenamematchpattern <RegularExpression>]
        <PermissionMatch>* [<PermissionMatchMode>] [<PermissionMatchAction>]
        [excludetrashed]
        [summary none|only|plus] [summaryuser <String>] [showsize]
gam <UserTypeEntity> show filecounts
        [((query <QueryDriveFile>) | (fullquery <QueryDriveFile>) | <DriveFileQueryShortcut>)
            (querytime<String> <Time>)*]
        [corpora <CorporaAttribute>]
        [select <SharedDriveEntity>]
        [anyowner|(showownedby any|me|others)]
        [showmimetype [not] <MimeTypeList>] [minimumfilesize <Integer>] [maximumfilesize <Integer>]
        [filenamematchpattern <RegularExpression>]
        <PermissionMatch>* [<PermissionMatchMode>] [<PermissionMatchAction>]
        [excludetrashed]
        [summary none|only|plus] [summaryuser <String>] [showsize]
```

By default, print filecounts displays counts of all files owned by the specified `<UserTypeEntity>`.

The `showsize` option displays the total size (in bytes) of the files counted.

See [Select files for Display file counts, list, tree](#select-files-for-display-file-counts-list-tree)

Use the `excludetrashed` option to suppress counting files in the trash.

By default, file counts for individual users are displayed; the `summary` option offers alternatives
that can display a summarization of file counts across all users specified in the command.
* `none` - No summary is displayed; this is the default
* `only` - Only the summary is displayed, no individual user file counts are displayed
* `plus` - The summary is displayed in addition to the individual user file counts

The `summaryuser <String>` option  replaces the default summary user `Summary` with `<String>`.

### Example
Get file count summaries by OU; top level selector is ou, sub level selectors are ou_and_children
```
gam redirect csv ./TopLevelOUs.csv print ous showparent toplevelonly parentselector ou childselector ou_and_children fields orgunitpath
gam redirect csv ./FileCounts.csv multiprocess csv ./TopLevelOUs.csv gam "~orgUnitSelector" "~orgUnitPath" print filecounts excludetrashed summary only summaryuser "~orgUnitPath"
```

## Display file share counts
Print or show the share type counts of a user's files. These fields are displayed:
* Owner - The file owner
* Total - Total number of files
* Shared - Number of files shared
* Shared External - Number of files shared externally
* Shared Internal - Number of files shared internally
* anyone - Number of ACLs of type anyone, allowFileDiscovery = True
* anyoneWithLink - Number of ACLs of type anyone, allowFileDiscovery = False
* externalDomain - Number of ACLs of type domain, external domains, allowFileDiscovery = True
* externalDomainWithLink - Number of ACLs of type domain, external domains,  allowFileDiscovery = False
* internalDomain - Number of ACLs of type domain, internal domains, allowFileDiscovery = True
* internalDomainWithLink - Number of ACLs of type domain, internal domains, allowFileDiscovery = False
* externalGroup - Number of ACLs of type group, external domains
* internalGroup - Number of ACLs of type group, internal domains
* externalUser - Number of ACLs of type user, external domains
* internalUser - Number of ACLs of type user, internal domains
* deletedGroup - Number of ACLs to a deleted group
* deletedUser - Number of ACLs to a deleted user
```
gam <UserTypeEntity> print filesharecounts [todrive <ToDriveAttribute>*]
        [excludetrashed]
        [internaldomains <DomainNameList>]
        [summary none|only|plus] [summaryuser <String>]
gam <UserTypeEntity> show filesharecounts
        [excludetrashed]
        [internaldomains <DomainNameList>]
        [summary none|only|plus] [summaryuser <String>]
```

By default, print|show filesharecounts displays share type counts of all files owned by the specified `<UserTypeEntity>`.

Use the `excludetrashed` option to suppress counting files in the trash.

By default, `internaldomains <DomainNameList>` defaults to your primary domain; if you have other domains that
you consider internal, list all of them in `<DomainNameList>`.

By default, share type counts for individual users are displayed; the `summary` option offers alternatives
that can display a summarization of share type counts across all users specified in the command.
* `none` - No summary is displayed; this is the default
* `only` - Only the summary is displayed, no individual user share type counts are displayed
* `plus` - The summary is displayed in addition to the individual user share type counts

The `summaryuser <String>` option  replaces the default summary user `Summary` with `<String>`.

### Example
```
$ gam users testuser0,testuser1 show filesharecounts
Getting all Drive Files/Folders that match query ('me' in owners) for testuser0@domain.com (1/2)
Got 100 Drive Files/Folders that matched query ('me' in owners) for testuser0@domain.com...
Got 200 Drive Files/Folders that matched query ('me' in owners) for testuser0@domain.com...
Got 251 Drive Files/Folders that matched query ('me' in owners) for testuser0@domain.com...
User: testuser0@domain.com, Drive File/Folder: 251 (1/2)
  Total: 251
  Shared: 124
  Shared External: 27
  Shared Internal: 114
  anyone: 2
  anyoneWithLink: 7
  externalDomain: 1
  externalDomainWithLink: 2
  internalDomain: 1
  internalDomainWithLink: 8
  externalGroup: 1
  internalGroup: 5
  externalUser: 17
  internalUser: 167
  deletedGroup: 0
  deletedUser: 0
Getting all Drive Files/Folders that match query ('me' in owners) for testuser1@domain.com (2/2)
Got 100 Drive Files/Folders that matched query ('me' in owners) for testuser1@domain.com...
Got 186 Drive Files/Folders that matched query ('me' in owners) for testuser1@domain.com...
User: testuser1@domain.com, Drive File/Folder: 186 (2/2)
  Total: 186
  Shared: 85
  Shared External: 27
  Shared Internal: 72
  anyone: 2
  anyoneWithLink: 5
  externalDomain: 0
  externalDomainWithLink: 1
  internalDomain: 4
  internalDomainWithLink: 37
  externalGroup: 0
  internalGroup: 14
  externalUser: 20
  internalUser: 44
  deletedGroup: 0
  deletedUser: 0

$ gam users testuser0,testuser1 print filesharecounts summary plus
Getting all Drive Files/Folders that match query ('me' in owners) for testuser0@domain.com (1/2)
Got 100 Drive Files/Folders that matched query ('me' in owners) for testuser0@domain.com...
Got 200 Drive Files/Folders that matched query ('me' in owners) for testuser0@domain.com...
Got 251 Drive Files/Folders that matched query ('me' in owners) for testuser0@domain.com...
Getting all Drive Files/Folders that match query ('me' in owners) for testuser1@domain.com (2/2)
Got 100 Drive Files/Folders that matched query ('me' in owners) for testuser1@domain.com...
Got 186 Drive Files/Folders that matched query ('me' in owners) for testuser1@domain.com...
Owner,Total,Shared,Shared External,Shared Internal,anyone,anyoneWithLink,externalDomain,externalDomainWithLink,internalDomain,internalDomainWithLink,externalGroup,internalGroup,externalUser,internalUser,deletedGroup,deletedUser
testuser0@domain.com,251,124,27,114,2,7,1,2,1,8,1,5,17,167,0,0
testuser1@domain.com,186,85,27,72,2,5,0,1,4,37,0,14,20,44,0,0
Summary,437,209,54,186,4,12,1,3,5,45,1,19,37,211,0,0
```

## Display file tree
Display a list of file/folder names indented to show structure.
```
<FileTreeFieldName> ::=
        explicitlytrashed|
        filesize|
        id|
        mimetype|
        owners|
        parents|
        size|
        trashed
<FileTreeFieldNameList> ::= "<FileTreeFieldName>(,<FileTreeFieldName>)*"

gam <UserTypeEntity> print filetree [todrive <ToDriveAttribute>*]
        [select <DriveFileEntity> [selectsubquery <QueryDriveFile>]
            [depth <Number>]]
        [anyowner|(showownedby any|me|others)]
        [showmimetype [not] <MimeTypeList>] [minimumfilesize <Integer>] [maximumfilesize <Integer>]
        [filenamematchpattern <RegularExpression>]
        <PermissionMatch>* [<PermissionMatchMode>] [<PermissionMatchAction>]
        [excludetrashed]
        [fields <FileTreeFieldNameList>]
        (orderby <DriveFileOrderByFieldName> [ascending|descending])* [delimiter <Character>]
        [noindent] [stripcrsfromname]
gam <UserTypeEntity> show filetree
        [select <DriveFileEntity> [selectsubquery <QueryDriveFile>]
            [depth <Number>]]
        [anyowner|(showownedby any|me|others)]
        [showmimetype [not] <MimeTypeList>] [minimumfilesize <Integer>] [maximumfilesize <Integer>]
        [filenamematchpattern <RegularExpression>]
        <PermissionMatch>* [<PermissionMatchMode>] [<PermissionMatchAction>]
        [excludetrashed]
        [fields <FileTreeFieldNameList>]
        (orderby <DriveFileOrderByFieldName> [ascending|descending])* [delimiter <Character>]
        [stripcrsfromname]
```
By default, the file tree starting at the root and all orphans are shown.

See [Select files for Display file counts, list, tree](#select-files-for-display-file-counts-list-tree)

## File selection starting point for Display file tree
You can specify a specific folder from which to select files.
```
        [select <DriveFileEntity> [selectsubquery <QueryDriveFile>]
            [depth <Number>]]
```
* `select <DriveFileEntity>` - All files in the selected folder and below are shown.
* `selectsubquery <QueryDriveFile>` - Only the files in the selected folder that match the query are shown.

The `depth <Number>` argument controls which files or folders within a selected folder are listed.
* `depth -1` - all files and folders in the selected folder and below are listed; this is the default.
* `depth 0` - the files or folders within a selected folder are listed, no descendants are listed.
* `depth N` - the files and folders within the selected folder and those files and folders N levels below the selected folder are listed.

## Choose what fields to display
By default, only the file/folder name is displayed; use the following options to display additional fields.
* `fields <FileTreeFieldNameList>` - Display the selected fields.
* `delimiter <Character>` - If any field has multiple values, separate them with `<Character>`; the default value is `csv_output_field_delimiter` from `gam.cfg`.

For fields `explicitlytrashed` and `trashed`, only True values are shown with `show filetree`; True and False values are shown with `print filetree`.

For `print filetree`, use the `noindent` option to eliminate the indentation in front of the file name.

The `stripcrsfromname` option strips nulls, carriage returns and linefeeds from drive file names.
This option is special purpose and will not generally be used.

### Examples
Show full file tree including the file id and mimetype:
```
gam user testuser show filetree fields id,mimetype
```
Show file tree starting at the folder named "Middle Folder" and 2 levels deeper
```
gam user testuser show filetree select drivefilename "Middle Folder" depth 2
```
## Display file list
Display a list of file/folder details in CSV format.
```
gam <UserTypeEntity> print|show filelist [todrive <ToDriveAttribute>*]
        [((query <QueryDriveFile>) | (fullquery <QueryDriveFile>) | <DriveFileQueryShortcut>)
            (querytime<String> <Time>)*]
        [choose <DriveFileNameEntity>|<DriveFileEntityShortcut>]
        [corpora <CorporaAttribute>]
        [select <DriveFileEntity> [selectsubquery <QueryDriveFile>]
            [(norecursion [<Boolean>])|(depth <Number>)] [showparent]]
        [anyowner|(showownedby any|me|others)]
        [showmimetype [not] <MimeTypeList>] [minimumfilesize <Integer>] [maximumfilesize <Integer>]
        [filenamematchpattern <RegularExpression>]
        <PermissionMatch>* [<PermissionMatchMode>] [<PermissionMatchAction>] [pmfilter] [oneitemperrow]
        [excludetrashed]
        [maxfiles <Integer>] [nodataheaders <String>]
        [countsonly [summary none|only|plus] [summaryuser <String>] [showsource] [showsize]] [countsrowfilter]
        [filepath|fullpath [pathdelimiter <Character>] [addpathstojson] [showdepth]] [buildtree]
        [allfields|<DriveFieldName>*|(fields <DriveFieldNameList>)]
        [showdrivename] [showshareddrivepermissions]
        [(showlabels details|ids)|(includelabels <DriveLabelIDList>)]
        [showparentsidsaslist] [showpermissionslast]
        (orderby <DriveFileOrderByFieldName> [ascending|descending])* [delimiter <Character>]
        [stripcrsfromname]
        (addcsvdata <FieldName> <String>)*
        [formatjson [quotechar <Character>]]
```
By default, `print filelist` displays all files owned by the specified `<UserTypeEntity>`.

When `allfields` is specified (or no fields are specified), use `showshareddrivepermissions` to display permissions
when shared drives are queried/selected. In this case, the Drive API returns the permission IDs
but not the permissions themselves so GAM makes an additional API call per file to get the permissions.

See [Select files for Display file counts, list, tree](#select-files-for-display-file-counts-list-tree)

## File selection by name and entity shortcuts for Display file list
Select a subset of files by pre-defined queries.

These options define a complete query, eliminating the initial "`me` in owners".
The `<DriveFileEntityShortcut>` option was added in version 5.04.00.
```
<DriveFileNameEntity> ::=
        (anyname <DriveFileName>) | (anyname:<DriveFileName>) |
        (anydrivefilename <DriveFileName>) | (anydrivefilename:<DriveFileName>) |
        (name <DriveFileName>) | (name:<DriveFileName>) |
        (drivefilename <DriveFileName>) | (drivefilename:<DriveFileName>) |
        (othername <DriveFileName>) | (othername:<DriveFileName>) |
        (otherdrivefilename <DriveFileName>) | (otherdrivefilename:<DriveFileName>)

<DriveFileEntityShortcut> ::=
        alldrives |
        mydrive |
        mydrive_any |
        mydrive_me |
        mydrive_others |
        mydrive_with_orphans |
        onlyteamdrives|onlyshareddrives |
        orphans |
        ownedby_any |
        ownedby_me |
        ownedby_others |
        root |
        root_with_orphans |
        sharedwithme |
        sharedwithme_mydrive |
        sharedwithme_notmydrive

choose <DriveFileNameEntity>|<DriveFileEntityShortcut>
```
Definition of `<DriveFileEntityShortcut>`:
* `alldrives` - All files accessible by the user; `My Drive` including orphans, `Shared with me`, `Shared drives`
* `mydrive` - All files in `My Drive` excluding orphans; ownership controlled by `showownedby`
* `mydrive_any` - All files in `My Drive` including orphans owned by anyone
* `mydrive_me` - All files in `My Drive` including orphans owned by the user; `'me' in owners`
* `mydrive_others` - All files in `My Drive` excluding orphans owned by others; `not 'me' in owners`
* `mydrive_with_orphans` - All files in `My Drive` including orphans; ownership controlled by `showownedby`
* `onlyshareddrives` - All files in `Shared drives` accessible by the user
* `onlyteamdrives` - All files in `Shared drives` accessible by the user
* `orphans` - All files in `My Drive` whose parentage doesn't lead to `My Drive`; `'me' in owners`
* `ownedby_any` - All files in `My Drive` including orphans and `Shared with me` owned by anyone
* `ownedby_me` - All files in `My Drive` including orphans owned by the user; `'me' in owners`
* `ownedby_others` - All files in `My Drive` excluding orphans and `Shared with me` owned by others; `not 'me' in owners`
* `root` - All files in `My Drive` excluding orphans; ownership controlled by `showownedby`
* `root_with_orphans` - All files in `My Drive` including orphans; ownership controlled by `showownedby`
* `sharedwithme` - All files in `My Drive` and `Shared with me` owned by others; `not 'me' in owners`
* `sharedwithme_mydrive` - All files in `My Drive` owned by others; `not 'me' in owners`
* `sharedwithme_notmydrive` - All files in `Shared with me` but not in `My Drive`; `not 'me' in owners`

## File selection based on permission matching
Use the following option to select a subset of files based on their permissions.
* `<PermissionMatch>* [<PermissionMatchAction>]` - Use permission matching to select files

## File selection starting point for Display file list
You can specify a specific folder from which to select files.
```
select <DriveFileEntity> [selectsubquery <QueryDriveFile>]
    [norecursion|(depth <Number>)] [showparent]
```
These options can be used instead of the query options to select a specific folder to display.
* `select <DriveFileEntity>` - All files in the selected folder and below are shown.
  * To select the root folder of My Drive, use its `<DriveFolderID>` obtained by `gam user <UserItem> show fileinfo root id`
    * `select <IDfrom Above>`
  * Starting in version 6.22.14, you can select the root folder of My Drive with `rootid`.
    * `select rootid`
* `selectsubquery <QueryDriveFile>` - Only the files in the selected folder that match the query are shown.

The `norecursion` and `depth <Number>` arguments control which files or folders within a selected folder are listed.
* `norecursion` or `norecursion true` - no files and folders in the selected folder and below are listed
* `depth -1` - all files and folders in the selected folder and below are listed; this is the default.
* `depth 0` - the files or folders within the selected folder are listed, no descendants are listed.
* `depth N` - the files and folders within the selected folder and those files and folders N levels below the selected folder are listed.

By default, when a folder is selected, only its contents are displayed.
* `showparent` - The selected folder is also displayed.

## Choose what fields to display
If no query or select is performed, use these options to get file path information:
* `filepath|fullpath` - For files and folders, display the full path(s) to them starting at the root (My Drive)
* `addcsvdata <FieldName> <String>` - Add additional columns of data from the command line to the output
* `addpathstojson` - When this option and `formatjson` are specified, the path information will be included in the
JSON data rather than as additional columns

When used with `filepath` or `fullpath`, `showdepth` will display a `depth` column.
Files/folders directly in `My Drive` are at depth 0, the depth increases by 1
for each containing folder. For files with multiple parents, the maximum depth is displayed.

If a query or select is performed, use these options to get file path information:
* `filepath` - For files, no path information is shown; for folders, the paths of all of its children are shown starting at the selected folder
* `fullpath` - For files and folders, display the full path(s) to them starting at the root (My Drive or Shared Drive)
* `addpathstojson` - When this option and `formatjson` are specified, the path information will be included in the
JSON data rather than as additional columns

By default, file path components are separated by `/`; use `pathdelimiter <Character>` to use `<Character>` as the separator.

By default, only the fields `id` and `webViewLink` are displayed.
* `allfields` - Display all file fields
* `<DriveFieldName>*` - Select individual fields for display
* `fields <DriveFieldNameList>` - Select a list of fields for display
* `orderby <DriveFileOrderByFieldName> [ascending|descending])*` - Select the order in which the files are displayed
* `delimiter <Character>` - Specifiy the `<Character>` to separate items in the fields: `parentsIds, permissionIds, spaces`; the default value is `csv_output_field_delimiter` from `gam.cfg`.

When `allfields` is specified, use `showdrivename` to display Shared(Team) Drive names.
An additional API call is required to get each Shared(Team) Drive name; the names are cached so there is only one additional
API call per Shared(Team) Drive.

By default, when file parents are displayed, the columns displayed are:
```
...,parents,parents.0.id`,parents.0.isRoot,parents.1.id,parents.1.isRoot,...
```
The `parents` column indicates the number of parents a file has and there are discrete entries for each parent.

The `showparentsidsaslist` option changes the output to be only two columns:
```
...,parents,parentsIds,...
```
The `parents` column indicates the number of parents a file has and the `parentsIds` column is a list of the parent IDs
separated by `delimiter <Character>`; the default value is `csv_output_field_delimiter` from `gam.cfg`.
There is no `isRoot` information displayed. This option allows you to reference all of a files parents with
`addparents <DriveFolderIDList>` or `removeparents <DriveFolderIDList>` wn updating a file.

By default, no Drive Label information is displayed. Use the following options to display this information;
an API call per file is required to get the information.
* `showlabels details`
The columns displayed are:
```
...labels,labels.0.id,labels.0.revisionId,labels.1.id,labels.1.revisionId,...
```
The `labels` column indicates the number of drive labels a file has and there are discrete entries for each label.

* `showlabels ids`
```
...labels,labelsIds,...
```
The `labels` column indicates the number of drive labels a file has and the `labelssIds` column is a list of the drive label IDs
separated by `delimiter <Character>`; the default value is `csv_output_field_delimiter` from `gam.cfg`.

By default, all ACLS are displayed; use the following option in conjunction with `<PermissionMatch>* [<PermissionMatchAction>]`
to select a subset of files based on their permissions and to display only those permissions.
* `pmfilter` - Use permission matching to display a subset of the ACLs for each file

By default, all ACLs are displayed sorted with the other fields, the `showpermissionslast` option
causes GAM to display all `permissions` fields as the right-most columns in the CSV file. This option does not apply
when `formatjson` is specified.

By default, all ACLs are displayed with the other file fields on a single row.
* `oneitemperrow` - Display each of a files ACls on a separate row with all of the other file fields.
This produces a CSV file that can be used in subsequent commands without further script processing.

The `countsonly` option doesn't display any indididual file data, it lists the total number of files that the use can access
and the mumber of files by MIME type.

The `countsonly` suboption `summary none|only|plus` specifies display of a summarization of file counts across all users specified in the command.
* `none` - No summary is displayed; this is the default
* `only` - Only the summary is displayed, no individual user file counts are displayed
* `plus` - The summary is displayed in addition to the individual user file counts

The `summaryuser <String>` option  replaces the default summary user `Summary` with `<String>`.

The `countsonly` suboption `showsource` adds additional columns `Source` and `Name` that identify the top level folder ID and Name from which the counts are derived.

The `countsonly` suboption `showsize` adds an additional column `Size` that indicates the total size (in bytes) of the files represented on the row.

By default, when `countsonly` is specified, GAM applies `config csv_output_row_filter` to the file details to select which files are counted.
Use the `countsrowfilter` option to have GAM to apply `config csv_output_row_filter` to the file counts rather than the file details.

The `stripcrsfromname` option strips nulls, carriage returns and linefeeds from drive file names.
This option is special purpose and will not generally be used.

By default, Gam displays the information as columns of fields; the following option causes the output to be in JSON format,
* `formatjson` - Display the fields in JSON format.

By default, when writing CSV files, Gam uses a quote character of double quote `"`. The quote character is used to enclose columns that contain
the quote character itself, the column delimiter (comma by default) and new-line characters. Any quote characters within the column are doubled.
When using the `formatjson` option, double quotes are used extensively in the data resulting in hard to read/process output.
The `quotechar <Character>` option allows you to choose an alternate quote character, single quote for instance, that makes for readable/processable output.
`quotechar` defaults to `gam.cfg/csv_output_quote_char`. When uploading CSV files to Google, double quote `"` should be used.

### Examples
List all files/folders owned by the user:
```
gam user testuser print filelist
```
List all files/folders owned by the user that begin with the word 'Test':
```
gam user testuser print filelist query "title contains 'Test'"
```
List all files/folders owned by any user that are starred and have been modified in the last year:
```
gam user testuser print filelist fullquery "starred = true and modifiedTime >= '#querytimelastyear#'" querytimelastyear -1y
```
List the file with the most recent modification date:
```
gam user testuser print filelist orderby modifiedtime descending maxfiles 1
```
List the file with the oldest modification date:
```
gam user testuser print filelist orderby modifiedtime ascending maxfiles 1
```
List all files/folders without a parent, owned by anyone, do not show their descendants:
```
gam user testuser print filelist select orphans showownedby any depth 0
```
List all files/folders and their descendents, owned by the user, in the folder 'Top Folder':
```
gam user testuser print filelist select drivefilename 'Top Folder' showownedby me
```
List all files whose name ends in ".exe" that are in the folder named "Folder Name" and its sub-folders:
```
gam user testuser print filelist select drivefilename "Folder Name" filenamematchpattern ".*\.exe"
```
If you only want files whose name ends in ".exe" that are directly in the folder named "Folder Name":
```
gam user testuser print filelist select drivefilename "Folder Name" depth 0 filenamematchpattern ".*\.exe"
```
List all Meet recordings older than 30 days.
```
gam user testuser print filelist select drivefilename "Meet Recordings" querytime30d -30d selectsubquery "modifiedTime<'#querytime30d#'"
```
List all files owned by the user and shared with others; i.e., files with ACLs with a role other than owner.
```
gam user testuser print filelist fields id,name,basicpermissions pm not role owner em
```
List all files owned by the user and shared with others; i.e., files with ACLs with a role other than owner.
Display a separate row for each ACL.
```
gam user testuser print filelist fields id,name,basicpermissions pm not role owner em onitemperrow
```
List all files owned by the user and shared with others; i.e., files with ACLs with a role other than owner.
Display a separate row for each ACL; only display the matching ACLS.
```
gam user testuser print filelist fields id,name,basicpermissions pm not role owner em onitemperrow pmfilter
```
List a user's shortcuts and information about the target files.
```
gam redirect csv ./TSShortcuts.csv user user@domain.com print filelist fields id,name,parents,shortcutdetails showmimetype gshortcut
Headers
Owner,id,name,parents,parents.0.id,parents.0.isRoot,shortcutDetails.targetId,shortcutDetails.targetMimeType

For each shortcut, get the target file information; add the shortcut id, name and parent to the output
gam redirect csv ./TSShortcutFiles.csv multiprocess csv ./TSShortcuts.csv gam user user@domain.com print filelist select "~shortcutDetails.targetId" norecursion showownedby any
    fields id,name,mimetype,parents,owners.emailaddress addcsvdata shortcut.id "~id" addcsvdata shortcut.name "~name" addcsvdata shortcut.parents "~parents.0.id"
Headers
Owner,id,name,mimeType,owners,owners.0.emailAddress,parents,parents.0.id,parents.0.isRoot,shortcut.id,shortcut.name,shortcut.parents
```

### Examples using csv_output_row_filter
Display file counts for users with files of size greater that 100MB, `csv_output_row_filter`
is applied to the file details.
```
gam config csv_output_row_filter "size:count>100000000" all users print filelist countsonly fields size
```
Display file counts for users with more than 100 `video/mp4` files, `csv_output_row_filter`
is applied to the file counts.
```
gam config csv_output_row_filter "video/mp4:count>100" csv_output_header_filter "Owner,video/mp4" all users print filelist countsonly countsrowfilter
```

### Examples showing file paths
All files, no file path
```
$ gam user testuser print filelist title
Getting all Drive Files/Folders that match query ('me' in owners) for testuser@domain.com
Got 11 Drive Files/Folders for testuser@domain.com...
Owner,title
testuser@domain.com,Bottom Sheet 12
testuser@domain.com,Bottom Sheet 11
testuser@domain.com,Bottom Doc 22
testuser@domain.com,Bottom Doc 21
testuser@domain.com,Bottom Folder 22
testuser@domain.com,Bottom Folder 21
testuser@domain.com,Bottom Folder 12
testuser@domain.com,Bottom Folder 11
testuser@domain.com,Middle Folder 2
testuser@domain.com,Middle Folder 1
testuser@domain.com,Top Folder
```
No `select` or `query`, `filepath` and `fullpath` give same result
```
$ gam user testuser print filelist title filepath
Getting all Drive Files/Folders that match query ('me' in owners) for testuser@domain.com
Got 11 Drive Files/Folders for testuser@domain.com...
Owner,title,paths,path.0
testuser@domain.com,Bottom Sheet 12,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 12/Bottom Sheet 12
testuser@domain.com,Bottom Sheet 11,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 11/Bottom Sheet 11
testuser@domain.com,Bottom Doc 22,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 22/Bottom Doc 22
testuser@domain.com,Bottom Doc 21,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 21/Bottom Doc 21
testuser@domain.com,Bottom Folder 22,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 22
testuser@domain.com,Bottom Folder 21,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 21
testuser@domain.com,Bottom Folder 12,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 12
testuser@domain.com,Bottom Folder 11,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 11
testuser@domain.com,Middle Folder 2,1,My Drive/Top Folder/Middle Folder 2
testuser@domain.com,Middle Folder 1,1,My Drive/Top Folder/Middle Folder 1
testuser@domain.com,Top Folder,1,My Drive/Top Folder

$ gam user testuser print filelist title fullpath
Getting all Drive Files/Folders that match query ('me' in owners) for testuser@domain.com
Got 11 Drive Files/Folders for testuser@domain.com...
Owner,title,paths,path.0
testuser@domain.com,Bottom Sheet 12,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 12/Bottom Sheet 12
testuser@domain.com,Bottom Sheet 11,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 11/Bottom Sheet 11
testuser@domain.com,Bottom Doc 22,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 22/Bottom Doc 22
testuser@domain.com,Bottom Doc 21,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 21/Bottom Doc 21
testuser@domain.com,Bottom Folder 22,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 22
testuser@domain.com,Bottom Folder 21,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 21
testuser@domain.com,Bottom Folder 12,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 12
testuser@domain.com,Bottom Folder 11,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 11
testuser@domain.com,Middle Folder 2,1,My Drive/Top Folder/Middle Folder 2
testuser@domain.com,Middle Folder 1,1,My Drive/Top Folder/Middle Folder 1
testuser@domain.com,Top Folder,1,My Drive/Top Folder
```
Select a folder, no file path
```
$ gam user testuser print filelist title select drivefilename "Top Folder"
Getting all Drive Files/Folders that match query ('me' in owners and title = 'Top Folder') for testuser@domain.com
Got 1 Drive File/Folder for testuser@domain.com...
Owner,title
testuser@domain.com,Middle Folder 2
testuser@domain.com,Bottom Folder 22
testuser@domain.com,Bottom Doc 22
testuser@domain.com,Bottom Folder 21
testuser@domain.com,Bottom Doc 21
testuser@domain.com,Middle Folder 1
testuser@domain.com,Bottom Folder 12
testuser@domain.com,Bottom Sheet 12
testuser@domain.com,Bottom Folder 11
testuser@domain.com,Bottom Sheet 11
```
Select a folder, no file path, show parent (selected) folder
```
$ gam user testuser print filelist title select drivefilename "Top Folder" showparent
Getting all Drive Files/Folders that match query ('me' in owners and title = 'Top Folder') for testuser@domain.com
Got 1 Drive File/Folder for testuser@domain.com...
Owner,title
testuser@domain.com,Top Folder
testuser@domain.com,Middle Folder 2
testuser@domain.com,Bottom Folder 22
testuser@domain.com,Bottom Doc 22
testuser@domain.com,Bottom Folder 21
testuser@domain.com,Bottom Doc 21
testuser@domain.com,Middle Folder 1
testuser@domain.com,Bottom Folder 12
testuser@domain.com,Bottom Sheet 12
testuser@domain.com,Bottom Folder 11
testuser@domain.com,Bottom Sheet 11
```
Select a folder, partial file path
```
$ gam user testuser print filelist title select drivefilename "Top Folder" filepath
Getting all Drive Files/Folders that match query ('me' in owners and title = 'Top Folder') for testuser@domain.com
Got 1 Drive File/Folder for testuser@domain.com...
Owner,title,paths,path.0
testuser@domain.com,Middle Folder 2,1,Top Folder/Middle Folder 2
testuser@domain.com,Bottom Folder 22,1,Top Folder/Middle Folder 2/Bottom Folder 22
testuser@domain.com,Bottom Doc 22,1,Top Folder/Middle Folder 2/Bottom Folder 22/Bottom Doc 22
testuser@domain.com,Bottom Folder 21,1,Top Folder/Middle Folder 2/Bottom Folder 21
testuser@domain.com,Bottom Doc 21,1,Top Folder/Middle Folder 2/Bottom Folder 21/Bottom Doc 21
testuser@domain.com,Middle Folder 1,1,Top Folder/Middle Folder 1
testuser@domain.com,Bottom Folder 12,1,Top Folder/Middle Folder 1/Bottom Folder 12
testuser@domain.com,Bottom Sheet 12,1,Top Folder/Middle Folder 1/Bottom Folder 12/Bottom Sheet 12
testuser@domain.com,Bottom Folder 11,1,Top Folder/Middle Folder 1/Bottom Folder 11
testuser@domain.com,Bottom Sheet 11,1,Top Folder/Middle Folder 1/Bottom Folder 11/Bottom Sheet 11
```
Select a folder, partial file path, show parent (selected) folder
```
$ gam user testuser print filelist title select drivefilename "Top Folder" filepath showparent
Getting all Drive Files/Folders that match query ('me' in owners and title = 'Top Folder') for testuser@domain.com
Got 1 Drive File/Folder for testuser@domain.com...
Owner,title,paths,path.0
testuser@domain.com,Top Folder,1,Top Folder
testuser@domain.com,Middle Folder 2,1,Top Folder/Middle Folder 2
testuser@domain.com,Bottom Folder 22,1,Top Folder/Middle Folder 2/Bottom Folder 22
testuser@domain.com,Bottom Doc 22,1,Top Folder/Middle Folder 2/Bottom Folder 22/Bottom Doc 22
testuser@domain.com,Bottom Folder 21,1,Top Folder/Middle Folder 2/Bottom Folder 21
testuser@domain.com,Bottom Doc 21,1,Top Folder/Middle Folder 2/Bottom Folder 21/Bottom Doc 21
testuser@domain.com,Middle Folder 1,1,Top Folder/Middle Folder 1
testuser@domain.com,Bottom Folder 12,1,Top Folder/Middle Folder 1/Bottom Folder 12
testuser@domain.com,Bottom Sheet 12,1,Top Folder/Middle Folder 1/Bottom Folder 12/Bottom Sheet 12
testuser@domain.com,Bottom Folder 11,1,Top Folder/Middle Folder 1/Bottom Folder 11
testuser@domain.com,Bottom Sheet 11,1,Top Folder/Middle Folder 1/Bottom Folder 11/Bottom Sheet 11
```
Select a folder, full file path
```
$ gam user testuser print filelist title select drivefilename "Top Folder" fullpath
Getting all Drive Files/Folders that match query ('me' in owners and title = 'Top Folder') for testuser@domain.com
Got 1 Drive File/Folder for testuser@domain.com...
Owner,title,paths,path.0
testuser@domain.com,Middle Folder 2,1,My Drive/Top Folder/Middle Folder 2
testuser@domain.com,Bottom Folder 22,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 22
testuser@domain.com,Bottom Doc 22,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 22/Bottom Doc 22
testuser@domain.com,Bottom Folder 21,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 21
testuser@domain.com,Bottom Doc 21,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 21/Bottom Doc 21
testuser@domain.com,Middle Folder 1,1,My Drive/Top Folder/Middle Folder 1
testuser@domain.com,Bottom Folder 12,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 12
testuser@domain.com,Bottom Sheet 12,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 12/Bottom Sheet 12
testuser@domain.com,Bottom Folder 11,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 11
testuser@domain.com,Bottom Sheet 11,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 11/Bottom Sheet 11
```
Select a folder, full file path, show parent (selected) folder
```
$ gam user testuser print filelist title select drivefilename "Top Folder" fullpath showparent
Getting all Drive Files/Folders that match query ('me' in owners and title = 'Top Folder') for testuser@domain.com
Got 1 Drive File/Folder for testuser@domain.com...
Owner,title,paths,path.0
testuser@domain.com,Top Folder,1,My Drive/Top Folder
testuser@domain.com,Middle Folder 2,1,My Drive/Top Folder/Middle Folder 2
testuser@domain.com,Bottom Folder 22,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 22
testuser@domain.com,Bottom Doc 22,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 22/Bottom Doc 22
testuser@domain.com,Bottom Folder 21,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 21
testuser@domain.com,Bottom Doc 21,1,My Drive/Top Folder/Middle Folder 2/Bottom Folder 21/Bottom Doc 21
testuser@domain.com,Middle Folder 1,1,My Drive/Top Folder/Middle Folder 1
testuser@domain.com,Bottom Folder 12,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 12
testuser@domain.com,Bottom Sheet 12,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 12/Bottom Sheet 12
testuser@domain.com,Bottom Folder 11,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 11
testuser@domain.com,Bottom Sheet 11,1,My Drive/Top Folder/Middle Folder 1/Bottom Folder 11/Bottom Sheet 11
```

## File selection with a particular drive label
The Drive API doesn't support querying for a drive label, so GAM must do the filtering.

Get the label id.
```
gam show drivelabels
```

Find the label with properties:title: XXX where XXX is the desired label title, then get its id: value

List the files.
```
gam config csv_output_row_filter "labelInfo.labels.0.id:regex:PutLabelIdHere" user user@domain.com print filelist fields id,name,labelinfo includelabels PutLabelIdHere
```

Adjust the `fields` list as desired.

## Handle empty file lists
When you execute a `gam print filelist` command with a query or permission match, there may be no files output;
in this case, there is only a header row: `Owner`. Subsequent gam commands to process the file will fail.
```
$ gam redirect csv ./Files.csv user user@domain.com print filelist query "name contains 'abcd'" fields id,name
Getting all Drive Files/Folders that match query ('me' in owners and name contains 'abcd') for user@domain.com
Got 0 Drive Files/Folders that matched query ('me' in owners and name contains 'abcd') for user@domain.com...
$ more Files.csv
Owner
$ gam csv Files.csv gam user ~Owner show fileinfo ~id permissions
Command: /Users/admin/bin/gam csv Files.csv gam user ~Owner show fileinfo >>>~id<<< permissions

ERROR: Header "id" not found in CSV headers of "Owner".
Help: Syntax in file /Users/admin/bin/gam/GamCommands.txt
Help: Documentation is at https://github.com/taers232c/GAMADV-XTD3/wiki
```

Now, the fields you select will be output on the header row and the subsequent command will not fail.
```
$ gam redirect csv ./Files.csv user user@domain.com print filelist query "name contains 'abcd'" fields id,name
Getting all Drive Files/Folders that match query ('me' in owners and name contains 'abcd') for user@domain.com
Got 0 Drive Files/Folders that matched query ('me' in owners and name contains 'abcd') for user@domain.com...
$ more Files.csv
Owner,id,name
$ gam csv Files.csv gam user ~Owner show fileinfo ~id permissions
$
```

If you specify `allfields`, a predefined set of headers are output.
```
$ gam redirect csv ./Files.csv user user@domain.com print filelist query "name contains 'abcd'" allfields
Getting all Drive Files/Folders that match query ('me' in owners and name contains 'abcd') for user@domain.com
Got 0 Drive Files/Folders that matched query ('me' in owners and name contains 'abcd') for user@domain.com...
$ more Files.csv
Owner,id,name,owners.0.emailAddress,permissions,permissions.0.allowFileDiscovery,permissions.0.deleted,permissions.0.displayName,permissions.0.domain,permissions.0.emailAddress,permissions.0.expirationTime,permissions.0.id,permissions.0.permissionDetails,permissions.0.photoLink,permissions.0.role,permissions.0.teamDrivePermissionDetails,permissions.0.type
```

You can also specify the headers you want in the case that there are no files selected; your script could test for this value.
```
$ gam redirect csv ./Files.csv user user@domain.com print filelist query "name contains 'abcd'" allfields nodataheaders "BadNews-NoData"
Getting all Drive Files/Folders that match query ('me' in owners and name contains 'abcd') for user@domain.com
Got 0 Drive Files/Folders that matched query ('me' in owners and name contains 'abcd') for user@domain.com...
$ more Files.csv
BadNews-NoData
```
## Display disk usage
```
gam <UserTypeEntity> print diskusage <DriveFileEntity> [todrive <ToDriveAttribute>*]
        [anyowner|(showownedby any|me|others)]
        [pathdelimiter <Character>] [excludetrashed] [stripcrsfromname]
        (addcsvdata <FieldName> <String>)*
        [noprogress] [show all|summary|summaryandtrash]
```
For each folder in `<DriveFileEntity>`, the following items are displayed:
* `User` - The email address of the user in `<UserTypeEntity>`
* `Owner` - The email address of the owner of the folder; omitted when displaying disk usage on Shared Drives
* `ownedByMe` - True if the folder is owned by `User`, False otherwise; omitted when displaying disk usage on Shared Drives
* `id` - The folder ID
* `name` - The Folder name
* `trashed` - True if the folder has been trashed, either explicitly or from a trashed parent folder, False otherwise
* `explicitlyTrashed` - True if the folder has been explicitly trashed, as opposed to recursively trashed from a parent folder, False otherwise
* `directFileCount` - The number of files directly in the folder
* `directFileSize` - The sum of the sizes of the files directly in the folder
* `directFolderCount` - The number of folders directly in the folder
* `totalFileCount` - The number of files directly in the folder and all of its subfolders
* `totalFileSize` - The sum of the sizes of the files directly in the folder and all of its subfolders
* `totalFolderCount` - The number of folders directly in the folder and all of its subfolders
* `path` - The path of the folder

There is a final row detailing files and folders in the trash; it is omitted if `excludetrashed` or `show summary` are specified.
* `User` - The email address of the user in `<UserTypeEntity>`
* `Owner` - The email address of the user in `<UserTypeEntity>`
* `ownedByMe` - True
* `id` - Trash
* `name` - Trash
* `trashed` - True if there are any items in the trash
* `explicitlyTrashed` - True if any items have been explicitly trashed
* `directFileCount` - The number of explicitly trashed files
* `directFileSize` - The sum of the sizes of the explicitly trashed files 
* `directFolderCount` - The number of explicitly trashed folders
* `totalFileCount` - The number of files in the trash
* `totalFileSize` - The sum of the sizes of the files in the trash
* `totalFolderCount` - The number of folders in the trash
* `path` - Trash

By default, files owned by the user are counted. These options update the current query with the desired ownership.
* `showownedby me` - Count files owned by the user; this is the default
* `showownedby any` or `anyowner` - Count files accessible by the user
* `showownedby others` - Count files not owned by the user

All folders are counted, regardless of ownership.

By default, file path components are separated by `/`; use `pathdelimiter <Character>` to use `<Character>` as the separator.

Use the `excludetrashed` option to suppress counting files and folders in the trash.

The `stripcrsfromname` option strips nulls, carriage returns and linefeeds from drive file names.
Use this option if you discover filenames containing these special characters; it is not common.

Add additional columns of data from the command line to the output:
* `addcsvdata <FieldName> <String>`

By default, progress messages are displayed for each folder, use `noprogress` to suppress these messages.

Use the `show` option to control the display of data:
* `show all` - Display a row for every folder in `<DriveFileEntity>` and a row detailing items in the trash when `excludetrashed` is omitted. This is the default.
* `show summary` - Display a single row for the first folder in `<DriveFileEntity>`
* `show summaryandtrash` - Display a single row for the first folder in `<DriveFileEntity>` and a row detailing items in the trash when `excludetrashed` is omitted.

### Examples
```
$ gam redirect csv ./MyDriveUsage.csv user testsimple@domain.com print diskusage mydrive 
User: testsimple@domain.com, Print 1 Drive Disk Usage
$ more MyDriveUsage.csv
User,Owner,id,name,ownedByMe,trashed,explicitlyTrashed,directFileCount,directFileSize,directFolderCount,totalFileCount,totalFileSize,totalFolderCount,path
testsimple@domain.com,testsimple@domain.com,012YenC8f12ALUk9PVA,My Drive,,False,False,100,138212,24,167,189598,79,My Drive
testsimple@domain.com,testsimple@domain.com,456YenC8f12ALfndaQ1NHc0RtUG92Y1BIUUl4bjVBRmNkWG5oakNqVVFDcXJWOHNmdFlwZmc,Classroom,True,False,False,0,0,15,9,6840,17,My Drive/Classroom
...
testsimple@domain.com,testsimple@domain.com,1bHS_Tp77W3KSGRNSs_jP1RhAJhIGRCaI,XferFolder,True,False,False,1,1024,0,1,1024,0,My Drive/XferFolder
testsimple@domain.com,testsimple@domain.com,Trash,Trash,,True,True,0,0,1,3,3072,9,Trash

$ gam redirect csv ./MyDriveUsage.csv user testsimple@domain.com print diskusage mydrive show summaryandtrash
User: testsimple@domain.com, Print 1 Drive Disk Usage
$ more MyDriveUsage.csv 
User,Owner,id,name,ownedByMe,trashed,explicitlyTrashed,directFileCount,directFileSize,directFolderCount,totalFileCount,totalFileSize,totalFolderCount,path
testsimple@domain.com,testsimple@domain.com,012YenC8f12ALUk9PVA,My Drive,,False,False,100,138212,24,167,189598,79,My Drive
testsimple@domain.com,testsimple@domain.com,Trash,Trash,,True,True,0,0,1,3,3072,9,Trash

$ gam redirect csv ./MyDriveUsage.csv user testsimple@domain.com print diskusage shareddriveid 0AL5LiIe4dqxZUk9PVA  show summaryandtrash
User: testsimple@domain.com, Print 1 Drive Disk Usage
$ more MyDriveUsage.csv 
User,id,name,trashed,explicitlyTrashed,directFileCount,directFileSize,directFolderCount,totalFileCount,totalFileSize,totalFolderCount,path
testsimple@domain.com,0125LiIe4dqxZUk9PVA,TS Shared Drive 1,False,False,16,6144,7,42,73799,25,SharedDrives/TS Shared Drive 1
testsimple@domain.com,Trash,Trash,True,True,1,1024,0,1,1024,0,Trash
```
