You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Google Drive文件夹及子文件夹内的所有文件批量应用标签?

Batch Apply Tags to Entire Folder Tree in Google Drive

Great question—manually tagging files across nested folders is such a time sink, especially when your structure is alphabetically organized with small batches per subfolder. Here are two reliable methods to skip the repetitive work and apply tags to every file in a folder (and all its subfolders) in one go:

Method 1: Use Google Apps Script (Custom Automated Workflow)

This is the most flexible option, perfect for handling large folder trees without manual selection limits.

Step-by-Step Setup:

  1. Open Google Apps Script (or from Google Drive: New > More > Google Apps Script).
  2. In the script editor, first enable the Drive API:
    • Click Services (left sidebar) > Add Service > Select Drive API (v3) > Click Add.
  3. Replace the default myFunction() code with the script below:
function batchApplyTagToFolderTree() {
  // Replace these values with your own
  const targetFolderId = "YOUR_FOLDER_ID"; // Get from folder URL (e.g., https://drive.google.com/drive/folders/[THIS_PART])
  const tagName = "YOUR_TARGET_TAG"; // Must match an existing tag in your Drive

  // Find the tag ID by name
  const allTags = Drive.Tags.list().tags;
  const targetTag = allTags.find(tag => tag.name === tagName);
  
  if (!targetTag) {
    console.log(`Error: Tag "${tagName}" not found. Double-check the tag name.`);
    return;
  }

  // Recursively process all files in folder and subfolders
  function processFolder(folder) {
    // Handle files in current folder
    const files = folder.getFiles();
    while (files.hasNext()) {
      const file = files.next();
      // Apply the tag to the file
      Drive.Files.update(
        { labelIds: [targetTag.id] },
        file.getId(),
        null,
        { fields: 'labelIds' }
      );
      console.log(`Tagged: ${file.getName()}`);
    }

    // Handle subfolders
    const subFolders = folder.getFolders();
    while (subFolders.hasNext()) {
      processFolder(subFolders.next());
    }
  }

  // Start the workflow
  const rootFolder = DriveApp.getFolderById(targetFolderId);
  processFolder(rootFolder);
  console.log("Batch tagging complete!");
}
  1. Replace YOUR_FOLDER_ID and YOUR_TARGET_TAG with your actual folder ID and tag name.
  2. Click the run button (▶️) and authorize the script when prompted (you’ll need to allow access to your Drive files).

Notes:

  • If you have tens of thousands of files, you may hit Google’s API quota limits. In that case, add a Utilities.sleep(100) inside the file loop to slow down requests.
  • The script will log every tagged file in the Executions tab so you can verify progress.

Method 2: Advanced Search + Bulk Selection (No Code Needed)

If you prefer a no-code approach, use Google Drive’s advanced search to select all files in the folder tree at once:

  1. Open Google Drive and paste this into the search bar (replace YOUR_FOLDER_ID with your folder’s ID):
    parents:"YOUR_FOLDER_ID"
    
    This search returns every file in the target folder and all its subfolders.
  2. Select the first file, then press Ctrl+A (Windows) or Cmd+A (Mac) to select all visible files.
  3. A prompt will appear at the top: "Select all X items that match this search"—click this to select every file in the results (even those not visible on the page).
  4. Right-click the selected files, hover over Tags, and check the tag you want to apply.

Notes:

  • This method works best for folder trees with fewer than ~5,000 files (larger sets may take time to load or cause browser slowdowns).
  • Make sure your tag is already created in Drive (via the left sidebar’s Tags menu) before starting.

内容的提问来源于stack exchange,提问作者Adam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 18:42:48