Folders are files that only contain metadata and can be used to organize files in Google Drive. They have the following properties:
- A folder is a file with the MIME type
application/vnd.google-apps.folder
and it has no extension. - The alias
root
can be used to refer to the root folder anywhere a file ID is provided.
For more information about Drive folder limits, see File and folder limits.
This guide explains how to perform some basic folder-related tasks.
Create a folder
To create a folder, use the files.create
method with the application/vnd.google-apps.folder
MIME
type and a title. The following code sample shows
how to create a folder using a client library:
Java
Python
Node.js
PHP
.NET
Create a file in a specific folder
To create a file in a specific folder, use the files.create
method and specify the folder ID in the
parents
property of the file.
The parents
property holds the ID of the parent folder containing the file.
The parents
property can be used when creating files in a top-level folder or
any other folder.
A file can only have one parent folder; specifying multiple parents isn't supported.
The following code sample shows how to create a file in a specific folder using a client library:
Java
Python
Node.js
PHP
.NET
Move files between folders
To move files, you must update the ID of the parents
property.
To add or remove parents for an existing file, use files.update
method with the addParents
and
removeParents
query parameters.
A file can only have one parent folder; specifying multiple parents isn't supported.
The following code sample shows how to move a file between folders using a client library:
Java
Python
Node.js
PHP
.NET
File and folder limits
Drive files and folders have some storage limits.
User-item limit
Each user can have up to 500 million items that were created by that account. When the limit is reached, the user can no longer create or upload items in Drive. They can still view and edit existing items. To create files again, users must permanently delete items or use a different account. For more information, see Trash or delete files and folders.
Objects that count toward this limit are:
- Items created or uploaded by the user in Drive
- Items created by the user but now owned by someone else
- Items in the trash
- Shortcuts
- Third-party shortcuts
Objects that don't count toward this limit are:
- Permanently-deleted items
- Items shared with the user but owned by someone else
- Items owned by the user but created by someone else
Attempts to add more than 500 million items returns an
activeItemCreationLimitExceeded
HTTP status code response.
Note that while there's no limit on the number of items a service account can own, the 500 million item limit applies to the number of items a service account can create.
Folder-item limit
Each folder in a user's My Drive has a limit of 500,000 items. This limit doesn't apply to the root folder of My Drive. Items that count toward this limit are:
- Folders
- Files. All file types, regardless of file ownership.
- Shortcuts. Counts as a single item within a folder, even if the item it points to isn't within that folder. For more information, see Create a shortcut to a Drive file.
- Third-party shortcuts. Counts as a single item within a folder, even if the item it points to isn't within that folder. For more information, see Create a shortcut file to content stored by your app.
For more information about folder limits, see Folder limits in Google Drive.
Folder-depth limit
A user's My Drive can't contain more than 100 levels of nested
folders. This means that a child folder cannot be stored under a folder that's
more than 99 levels deep. This limitation only applies to child folders. A child
file with a MIME type other than
application/vnd.google-apps.folder
is exempt from this limitation.
For example, in the following diagram a new folder can be nested inside folder number 99 but not inside folder number 100. However, folder number 100 can store files like any other Drive folder:
Attempts to add more than 100 levels of folders returns a
myDriveHierarchyDepthLimitExceeded
HTTP status code response.