建立雲端硬碟檔案的捷徑
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
捷徑是連結至 Google 雲端硬碟中其他檔案或資料夾的檔案。
快速鍵具有下列特徵:
application/vnd.google-apps.shortcut
MIME 類型。詳情請參閱「Google Workspace 和 Google 雲端硬碟支援的 MIME 類型」。
捷徑的 ACL 會沿用父項的 ACL。捷徑的 ACL 無法直接變更。
指向目標檔案或資料夾的 targetId
,也稱為「目標」。
targetMimeType
:指出目標的 MIME 類型。targetMimeType
用於判斷要顯示的類型圖示。建立捷徑時,目標的 MIME 類型會複製到 targetMimeType
欄位。
targetId
和 targetMimeType
欄位是 檔案資源中 shortcutDetails
欄位的一部分。
捷徑只能有一個上層項目。如果其他雲端硬碟位置需要捷徑檔案,可以將捷徑檔案複製到其他位置。
如果目標遭到刪除,或目前使用者失去目標的存取權,指向目標的使用者捷徑就會失效。
捷徑的標題可以與目標不同。建立捷徑時,系統會使用目標的標題做為捷徑標題。建立捷徑後,你可以分別變更捷徑和目標的標題。如果目標名稱變更,先前建立的捷徑會保留舊名稱。
捷徑的 MIME 類型可能會過時。雖然很少發生,但如果上傳不同類型的修訂版本,Blob 檔案的 MIME 類型就會變更,不過指向更新後檔案的任何捷徑都會保留原始 MIME 類型。舉例來說,如果將 JPG 檔案上傳至雲端硬碟,然後上傳 AVI 修訂版本,雲端硬碟會識別這項變更,並更新實際檔案的縮圖。不過,捷徑仍會顯示 JPG 縮圖。
在 Google 帳戶資料匯出 (又稱 Google 匯出) 中,捷徑會以 Netscape 書籤檔案表示,內含目標的連結。
詳情請參閱「使用 Google 雲端硬碟捷徑尋找檔案和資料夾」。
建立捷徑
如要建立捷徑,請將 MIME 類型設為 application/vnd.google-apps.shortcut
,將 targetId
設為捷徑應連結的檔案或資料夾,然後呼叫 files.create
建立捷徑。
下列範例說明如何使用用戶端程式庫建立捷徑:
Python
file_metadata = {
'name': 'FILE_NAME',
'mimeType': 'text/plain'
}
file = drive_service.files().create(body=file_metadata, fields='id').execute()
print('File ID: %s' % file.get('id'))
shortcut_metadata = {
'Name': 'SHORTCUT_NAME',
'mimeType': 'application/vnd.google-apps.shortcut',
'shortcutDetails': {
'targetId': file.get('id')
}
}
shortcut = drive_service.files().create(body=shortcut_metadata,
fields='id,shortcutDetails').execute()
print('File ID: %s, Shortcut Target ID: %s, Shortcut Target MIME type: %s' % (
shortcut.get('id'),
shortcut.get('shortcutDetails').get('targetId'),
shortcut.get('shortcutDetails').get('targetMimeType')))
Node.js
var fileMetadata = {
'name': 'FILE_NAME',
'mimeType': 'text/plain'
};
drive.files.create({
'resource': fileMetadata,
'fields': 'id'
}, function (err, file) {
if (err) {
// Handle error
console.error(err);
} else {
console.log('File Id: ' + file.id);
shortcutMetadata = {
'name': 'SHORTCUT_NAME',
'mimeType': 'application/vnd.google-apps.shortcut'
'shortcutDetails': {
'targetId': file.id
}
};
drive.files.create({
'resource': shortcutMetadata,
'fields': 'id,name,mimeType,shortcutDetails'
}, function(err, shortcut) {
if (err) {
// Handle error
console.error(err);
} else {
console.log('Shortcut Id: ' + shortcut.id +
', Name: ' + shortcut.name +
', target Id: ' + shortcut.shortcutDetails.targetId +
', target MIME type: ' + shortcut.shortcutDetails.targetMimeType);
}
}
}
});
更改下列內容:
- FILE_NAME:需要捷徑的檔案名稱。
- SHORTCUT_NAME:這個快速鍵的名稱。
根據預設,捷徑會建立在目前使用者的「我的雲端硬碟」中,且只會為目前使用者有權存取的檔案或資料夾建立捷徑。
搜尋捷徑
如要搜尋快速鍵,請使用查詢字串 q
,並搭配 files.list
篩選要傳回的快速鍵。
mimeType operator values
在此情況下:
- query_term 是要搜尋的查詢字詞或欄位。如要查看可用於篩選共用雲端硬碟的查詢字詞,請參閱「搜尋查詢字詞」。
- 運算子會指定查詢字詞的條件。如要查看每個查詢字詞可使用的運算子,請參閱「查詢運算子」。
- 值:用於篩選搜尋結果的特定值。
舉例來說,下列查詢字串會篩選搜尋結果,只傳回試算表檔案的所有捷徑:
q: mimeType='application/vnd.google-apps.shortcut' AND shortcutDetails.targetMimeType='application/vnd.google-apps.spreadsheet'
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[],[],null,["# Create a shortcut to a Drive file\n\n*Shortcuts* are files that link to other files or folders on Google Drive.\nShortcuts have these characteristics:\n\n- An `application/vnd.google-apps.shortcut` MIME type. For more information,\n see [Google Workspace \\& Google Drive supported MIME\n types](/workspace/drive/api/guides/mime-types).\n\n- The ACL for a shortcut inherits the ACL of the parent. The shortcut's ACL\n cannot be changed directly.\n\n- A `targetId` pointing to the target file or folder, also referred to as the\n \"target.\"\n\n- A `targetMimeType` indicating the MIME type for the target. The\n `targetMimeType` is used to determine the type icon to display. The target's\n MIME type is copied to the `targetMimeType` field when the shortcut is\n created.\n\n- The `targetId` and `targetMimeType` fields are part of the `shortcutDetails`\n field within the [file](/workspace/drive/api/reference/rest/v3/files) resource.\n\n- A shortcut can only have one parent. If a shortcut file is required in other\n Drive locations, the shortcut file can be copied to the\n additional locations.\n\n- When the target is deleted, or when the current user loses access to the\n target, the user's shortcut pointing to the target breaks.\n\n- The title of a shortcut can differ from the target. When a shortcut is\n created, the title of the target is used as the title of the shortcut. After\n creation, the shortcut's title and target's title can be changed\n independently. If the target's name is changed, previously created shortcuts\n retain the old title.\n\n- The MIME type of a shortcut can become stale. While rare, a blob file's MIME\n type changes when a revision of a different type is uploaded, but any\n shortcuts pointing to the updated file retain the original MIME type. For\n example, if you upload a JPG file to Drive, then upload an\n AVI revision, Drive identifies the change and updates the\n thumbnail for the actual file. However, the shortcut continues to have a JPG\n thumbnail.\n\n- In [Google Account Data\n Export](https://support.google.com/accounts/answer/3024190)\n also known as Google Takeout, shortcuts are represented as Netscape\n bookmark files containing links to the target.\n\nFor more information, see [Find files \\& folders with Google Drive\nshortcuts](https://support.google.com/drive/answer/9700156)\n.\n| **Important:** Previously, shortcuts were the term for files that pointed to content stored by an application. That type of \"shortcut\" was renamed to *third-party shortcut* . For further information, see [Create a shortcut file to\n| content stored by your app](/workspace/drive/api/guides/third-party-shortcuts).\n\nCreate a shortcut\n-----------------\n\nTo create a shortcut, set the MIME type to\n`application/vnd.google-apps.shortcut`, set the `targetId` to the file or folder\nthe shortcut should link to, and call [`files.create`](/workspace/drive/api/reference/rest/v3/files/create) to create a shortcut.\n| **Note:** If you're using V2 of the API, use [`files.insert`](/workspace/drive/api/v2/reference/files/insert).\n\nThe following examples show how to create a shortcut using a client library: \n\n### Python\n\n file_metadata = {\n 'name': '\u003cvar translate=\"no\"\u003eFILE_NAME\u003c/var\u003e',\n 'mimeType': 'text/plain'\n }\n file = drive_service.files().create(body=file_metadata, fields='id').execute()\n print('File ID: %s' % file.get('id'))\n shortcut_metadata = {\n 'Name': '\u003cvar translate=\"no\"\u003eSHORTCUT_NAME\u003c/var\u003e',\n 'mimeType': 'application/vnd.google-apps.shortcut',\n 'shortcutDetails': {\n 'targetId': file.get('id')\n }\n }\n shortcut = drive_service.files().create(body=shortcut_metadata,\n fields='id,shortcutDetails').execute()\n print('File ID: %s, Shortcut Target ID: %s, Shortcut Target MIME type: %s' % (\n shortcut.get('id'),\n shortcut.get('shortcutDetails').get('targetId'),\n shortcut.get('shortcutDetails').get('targetMimeType')))\n\n### Node.js\n\n var fileMetadata = {\n 'name': '\u003cvar translate=\"no\"\u003eFILE_NAME\u003c/var\u003e',\n 'mimeType': 'text/plain'\n };\n drive.files.create({\n 'resource': fileMetadata,\n 'fields': 'id'\n }, function (err, file) {\n if (err) {\n // Handle error\n console.error(err);\n } else {\n console.log('File Id: ' + file.id);\n shortcutMetadata = {\n 'name': '\u003cvar translate=\"no\"\u003eSHORTCUT_NAME\u003c/var\u003e',\n 'mimeType': 'application/vnd.google-apps.shortcut'\n 'shortcutDetails': {\n 'targetId': file.id\n }\n };\n drive.files.create({\n 'resource': shortcutMetadata,\n 'fields': 'id,name,mimeType,shortcutDetails'\n }, function(err, shortcut) {\n if (err) {\n // Handle error\n console.error(err);\n } else {\n console.log('Shortcut Id: ' + shortcut.id +\n ', Name: ' + shortcut.name +\n ', target Id: ' + shortcut.shortcutDetails.targetId +\n ', target MIME type: ' + shortcut.shortcutDetails.targetMimeType);\n }\n }\n }\n });\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eFILE_NAME\u003c/var\u003e: the file name requiring a shortcut.\n- \u003cvar translate=\"no\"\u003eSHORTCUT_NAME\u003c/var\u003e: the name for this shortcut.\n\nBy default, the shortcut is created on the current user's My\nDrive and shortcuts are only created for files or folders for\nwhich the current user has access.\n\nSearch for a shortcut\n---------------------\n\nTo search for a shortcut, use the query string `q` with\n[`files.list`](/workspace/drive/api/v3/reference/files/list) to filter the shortcuts to\nreturn.\n\n`mimeType `*operator values*\n\nWhere:\n\n- *query_term* is the query term or field to search upon. To view the query terms that can be used to filter shared drives, refer to [Search query\n terms](/workspace/drive/api/guides/ref-search-terms#file_properties).\n- *operator* specifies the condition for the query term. To view which operators you can use with each query term, refer to [Query operators](/workspace/drive/api/guides/ref-search-terms#operators).\n- *values* are the specific values you want to use to filter your search results.\n\nFor example, the following query string filters the search to return all\nshortcuts to spreadsheet files: \n\n q: mimeType='application/vnd.google-apps.shortcut' AND shortcutDetails.targetMimeType='application/vnd.google-apps.spreadsheet'"]]