递归 Google Drive 文件夹复制器(保留权限)
高级
这是一个File Management, Multimodal AI领域的自动化工作流,包含 22 个节点。主要使用 If, Set, Code, Filter, GoogleDrive 等节点。 递归 Google Drive 文件夹复制器(保留权限)
前置要求
- •Google Drive API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "54727bff0f5eeffb7bf9295509a4e3003a61b32ef52459f329ae99e7b5243230",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "4a36d370-4d43-4090-a8e0-6e2002550bfc",
"name": "设置配置",
"type": "n8n-nodes-base.set",
"position": [
-1328,
7968
],
"parameters": {
"values": {
"string": [
{
"name": "sourceFolderId",
"value": "1RdenWIrighEr6S53e25CkwYmUa7jAFjq"
},
{
"name": "targetFolderId",
"value": "13BQRVwg2QFGFRJstRzUt0CoO5w8bpS1I"
},
{
"name": "newFolderName",
"value": "Duplicated Folder"
}
]
},
"options": {}
},
"typeVersion": 1
},
{
"id": "4107d258-363c-4bf9-b5bf-3cfa2a8e7f8e",
"name": "创建主文件夹",
"type": "n8n-nodes-base.googleDrive",
"position": [
-1168,
7968
],
"parameters": {
"name": "={{ $json.newFolderName }}",
"driveId": {
"__rl": true,
"mode": "id",
"value": "={{ $json.targetFolderId }}"
},
"options": {},
"folderId": {
"__rl": true,
"mode": "list",
"value": "root",
"cachedResultName": "/ (Root folder)"
},
"resource": "folder"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "t01llYvLZwTdfjby",
"name": "Google Drive account 3"
}
},
"typeVersion": 3
},
{
"id": "5b2cdf23-9f31-4668-a5cc-0dd2d6b94129",
"name": "开始递归处理",
"type": "n8n-nodes-base.executeWorkflow",
"position": [
-1008,
7968
],
"parameters": {
"options": {},
"workflowId": {
"__rl": true,
"mode": "id",
"value": "{{ $workflow.id }}"
},
"workflowInputs": {
"value": {
"sourceFolderId": "={{ $node['Set Configuration'].json.sourceFolderId }}",
"targetFolderId": "={{ $json.id }}"
},
"schema": [
{
"id": "sourceFolderId",
"type": "string",
"display": true,
"required": false,
"displayName": "sourceFolderId",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "targetFolderId",
"type": "string",
"display": true,
"required": false,
"displayName": "targetFolderId",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": true
}
},
"typeVersion": 1.2
},
{
"id": "59abdaa3-b57e-4c75-a07e-1b8e720fb5ac",
"name": "主完成",
"type": "n8n-nodes-base.set",
"position": [
-848,
7968
],
"parameters": {
"values": {
"string": [
{
"name": "status",
"value": "Main folder duplication completed successfully"
},
{
"name": "sourceFolder",
"value": "={{ $node['Set Configuration'].json.sourceFolderId }}"
},
{
"name": "newMainFolder",
"value": "={{ $node['Create Main Folder'].json.id }}"
}
]
},
"options": {}
},
"typeVersion": 1
},
{
"id": "62d4d9eb-7c1d-48c8-bf0b-55269ee4caeb",
"name": "准备文件数据",
"type": "n8n-nodes-base.set",
"position": [
-864,
8448
],
"parameters": {
"values": {
"string": [
{
"name": "originalFileId",
"value": "={{ $node['Filter Files Only1'].json.id }}"
},
{
"name": "originalPermissions",
"value": "={{ JSON.stringify($node['Filter Files Only1'].json.permissions || []) }}"
},
{
"name": "newFileId",
"value": "={{ $json.id }}"
}
]
},
"options": {}
},
"typeVersion": 1
},
{
"id": "27f8d8ca-96ab-41e8-96db-33afdbd63959",
"name": "递归自调用",
"type": "n8n-nodes-base.executeWorkflow",
"position": [
-160,
8656
],
"parameters": {
"options": {},
"workflowId": {
"__rl": true,
"mode": "id",
"value": "{{ $workflow.id }}"
},
"workflowInputs": {
"value": {
"sourceFolderId": "={{ $json.originalFolderId }}",
"targetFolderId": "={{ $json.newFolderId }}"
},
"schema": [
{
"id": "sourceFolderId",
"type": "string",
"display": true,
"required": false,
"displayName": "sourceFolderId",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "targetFolderId",
"type": "string",
"display": true,
"required": false,
"displayName": "targetFolderId",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": true
}
},
"typeVersion": 1.2
},
{
"id": "15343d75-5c61-4de7-9ce4-4250ceccc03d",
"name": "层级完成",
"type": "n8n-nodes-base.set",
"position": [
64,
8464
],
"parameters": {
"values": {
"string": [
{
"name": "status",
"value": "Level processing completed"
}
]
},
"options": {}
},
"typeVersion": 1
},
{
"id": "0221146d-05a2-4c8f-a812-8b7ebe3e6a1c",
"name": "搜索文件夹内容1",
"type": "n8n-nodes-base.googleDrive",
"position": [
-1344,
8544
],
"parameters": {
"filter": {},
"options": {
"fields": [
"id",
"name",
"mimeType",
"permissions"
]
},
"resource": "fileFolder",
"returnAll": true,
"queryString": "'{{ $json.sourceFolderId }}' in parents and trashed = false",
"searchMethod": "query"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "t01llYvLZwTdfjby",
"name": "Google Drive account 3"
}
},
"typeVersion": 3
},
{
"id": "b437a057-3931-4c8e-ab6b-fab0f9f117dc",
"name": "仅筛选文件1",
"type": "n8n-nodes-base.filter",
"position": [
-1184,
8448
],
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.mimeType }}",
"value2": "application/vnd.google-apps.folder",
"operation": "notEqual"
}
]
}
},
"typeVersion": 1
},
{
"id": "ce118b58-cd56-4eaf-adea-e2e117eec17e",
"name": "仅筛选文件夹1",
"type": "n8n-nodes-base.filter",
"position": [
-1184,
8640
],
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ $json.mimeType }}",
"value2": "application/vnd.google-apps.folder"
}
]
}
},
"typeVersion": 1
},
{
"id": "4b80da29-fc25-48db-8aed-0f8c5ef13526",
"name": "复制文件1",
"type": "n8n-nodes-base.googleDrive",
"position": [
-1024,
8448
],
"parameters": {
"name": "={{ $json.name }}",
"fileId": {
"__rl": true,
"mode": "id",
"value": "={{ $json.id }}"
},
"driveId": {
"__rl": true,
"mode": "id",
"value": "={{ $node['Start'].json.targetFolderId }}"
},
"options": {},
"folderId": {
"__rl": true,
"mode": "list",
"value": "root",
"cachedResultName": "/ (Root folder)"
},
"operation": "copy",
"sameFolder": false
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "t01llYvLZwTdfjby",
"name": "Google Drive account 3"
}
},
"typeVersion": 3
},
{
"id": "38835c99-1d5c-4571-a505-ac3a57db699b",
"name": "检查文件权限1",
"type": "n8n-nodes-base.if",
"position": [
-704,
8448
],
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ JSON.parse($json.originalPermissions || '[]').length }}",
"value2": "0",
"operation": "larger"
}
]
}
},
"typeVersion": 1
},
{
"id": "9c25ddac-17de-45c9-b106-e13e740f8385",
"name": "准备文件权限1",
"type": "n8n-nodes-base.code",
"position": [
-512,
8272
],
"parameters": {
"jsCode": "const data = $input.first().json;\nconst newFileId = data.newFileId;\nconst originalPermissions = JSON.parse(data.originalPermissions || '[]');\nconst permissionsToApply = [];\nif (originalPermissions.length > 0) {\n for (const permission of originalPermissions) {\n if (permission.role !== 'owner' && permission.type && permission.role) {\n const permObj = {\n fileId: newFileId,\n type: permission.type,\n role: permission.role\n };\n if (permission.type === 'user' || permission.type === 'group') {\n if (permission.emailAddress) {\n permObj.emailAddress = permission.emailAddress;\n }\n } else if (permission.type === 'domain') {\n if (permission.domain) {\n permObj.domain = permission.domain;\n }\n }\n permissionsToApply.push(permObj);\n }\n }\n}\nif (permissionsToApply.length > 0) {\n return permissionsToApply.map(p => ({ json: p }));\n} else {\n return [];\n}"
},
"typeVersion": 2
},
{
"id": "b2927eae-9f20-49ab-a60b-8fc5e6784cdb",
"name": "应用文件权限1",
"type": "n8n-nodes-base.googleDrive",
"position": [
-352,
8272
],
"parameters": {
"fileId": "={{ $json.fileId }}",
"options": {
"sendNotificationEmail": false
},
"operation": "share",
"permissionsUi": {
"permissionsValues": {}
}
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "t01llYvLZwTdfjby",
"name": "Google Drive account 3"
}
},
"typeVersion": 3
},
{
"id": "bc443b2f-cc4b-4474-a78c-1d2ec1e4f500",
"name": "创建子文件夹1",
"type": "n8n-nodes-base.googleDrive",
"position": [
-1024,
8640
],
"parameters": {
"name": "={{ $json.name }}",
"driveId": {
"__rl": true,
"mode": "id",
"value": "={{ $node['Start'].json.targetFolderId }}"
},
"options": {},
"folderId": {
"__rl": true,
"mode": "list",
"value": "root",
"cachedResultName": "/ (Root folder)"
},
"resource": "folder"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "t01llYvLZwTdfjby",
"name": "Google Drive account 3"
}
},
"typeVersion": 3
},
{
"id": "01063a74-b9a6-4378-95b3-4dce49690f6f",
"name": "准备文件夹数据1",
"type": "n8n-nodes-base.set",
"position": [
-864,
8640
],
"parameters": {
"values": {
"string": [
{
"name": "originalFolderId",
"value": "={{ $node['Filter Folders Only1'].json.id }}"
},
{
"name": "originalPermissions",
"value": "={{ JSON.stringify($node['Filter Folders Only1'].json.permissions || []) }}"
},
{
"name": "newFolderId",
"value": "={{ $json.id }}"
}
]
},
"options": {}
},
"typeVersion": 1
},
{
"id": "d223bee5-58d6-4f38-8eab-9ec0a4101a08",
"name": "检查文件夹权限1",
"type": "n8n-nodes-base.if",
"position": [
-704,
8640
],
"parameters": {
"conditions": {
"string": [
{
"value1": "={{ JSON.parse($json.originalPermissions || '[]').length }}",
"value2": "0",
"operation": "larger"
}
]
}
},
"typeVersion": 1
},
{
"id": "e840b153-3754-4fb2-88b9-97a4e675e05c",
"name": "准备文件夹权限1",
"type": "n8n-nodes-base.code",
"position": [
-512,
8544
],
"parameters": {
"jsCode": "const data = $input.first().json;\nconst newFolderId = data.newFolderId;\nconst originalPermissions = JSON.parse(data.originalPermissions || '[]');\nconst permissionsToApply = [];\nif (originalPermissions.length > 0) {\n for (const permission of originalPermissions) {\n if (permission.role !== 'owner' && permission.type && permission.role) {\n const permObj = {\n fileId: newFolderId,\n type: permission.type,\n role: permission.role\n };\n if (permission.type === 'user' || permission.type === 'group') {\n if (permission.emailAddress) {\n permObj.emailAddress = permission.emailAddress;\n }\n } else if (permission.type === 'domain') {\n if (permission.domain) {\n permObj.domain = permission.domain;\n }\n }\n permissionsToApply.push(permObj);\n }\n }\n}\nif (permissionsToApply.length > 0) {\n return permissionsToApply.map(p => ({ json: p }));\n} else {\n return [];\n}"
},
"typeVersion": 2
},
{
"id": "f4a0f68a-947a-4f57-b3fd-18a5d819592b",
"name": "应用文件夹权限1",
"type": "n8n-nodes-base.googleDrive",
"position": [
-352,
8544
],
"parameters": {
"fileId": "={{ $json.fileId }}",
"options": {
"sendNotificationEmail": false
},
"operation": "share",
"permissionsUi": {
"permissionsValues": {}
}
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "t01llYvLZwTdfjby",
"name": "Google Drive account 3"
}
},
"typeVersion": 3
},
{
"id": "c3779818-366b-4a85-9422-8c72d4da956f",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1856,
7664
],
"parameters": {
"color": 3,
"width": 368,
"height": 1200,
"content": "# Google Drive 文件夹复制器(带权限)"
},
"typeVersion": 1
},
{
"id": "0720dc37-20be-486e-9e7e-6086927013d1",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1472,
7664
],
"parameters": {
"width": 1792,
"height": 480,
"content": "## 从此开始"
},
"typeVersion": 1
},
{
"id": "6fbd5544-e61b-4cfd-a982-271eed9f45db",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1472,
8160
],
"parameters": {
"width": 1792,
"height": 704,
"content": "## 核心递归引擎"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"Copy File1": {
"main": [
[
{
"node": "Prepare File Data",
"type": "main",
"index": 0
}
]
]
},
"Create Subfolder1": {
"main": [
[
{
"node": "Prepare Folder Data1",
"type": "main",
"index": 0
}
]
]
},
"Prepare File Data": {
"main": [
[
{
"node": "Check File Has Permissions1",
"type": "main",
"index": 0
}
]
]
},
"Set Configuration": {
"main": [
[
{
"node": "Create Main Folder",
"type": "main",
"index": 0
}
]
]
},
"Create Main Folder": {
"main": [
[
{
"node": "Start Recursive Processing",
"type": "main",
"index": 0
}
]
]
},
"Filter Files Only1": {
"main": [
[
{
"node": "Copy File1",
"type": "main",
"index": 0
}
]
]
},
"Filter Folders Only1": {
"main": [
[
{
"node": "Create Subfolder1",
"type": "main",
"index": 0
}
]
]
},
"Prepare Folder Data1": {
"main": [
[
{
"node": "Check Folder Has Permissions1",
"type": "main",
"index": 0
}
]
]
},
"Apply File Permission1": {
"main": [
[
{
"node": "Level Completion",
"type": "main",
"index": 0
}
]
]
},
"Recursive Call to Self": {
"main": [
[
{
"node": "Level Completion",
"type": "main",
"index": 0
}
]
]
},
"Search Folder Contents1": {
"main": [
[
{
"node": "Filter Files Only1",
"type": "main",
"index": 0
},
{
"node": "Filter Folders Only1",
"type": "main",
"index": 0
}
]
]
},
"Apply Folder Permission1": {
"main": [
[
{
"node": "Recursive Call to Self",
"type": "main",
"index": 0
}
]
]
},
"Prepare File Permissions1": {
"main": [
[
{
"node": "Apply File Permission1",
"type": "main",
"index": 0
}
]
]
},
"Start Recursive Processing": {
"main": [
[
{
"node": "Main Completion",
"type": "main",
"index": 0
}
]
]
},
"Check File Has Permissions1": {
"main": [
[
{
"node": "Prepare File Permissions1",
"type": "main",
"index": 0
}
],
[
{
"node": "Level Completion",
"type": "main",
"index": 0
}
]
]
},
"Prepare Folder Permissions1": {
"main": [
[
{
"node": "Apply Folder Permission1",
"type": "main",
"index": 0
}
]
]
},
"Check Folder Has Permissions1": {
"main": [
[
{
"node": "Prepare Folder Permissions1",
"type": "main",
"index": 0
}
],
[
{
"node": "Recursive Call to Self",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 文件管理, 多模态 AI
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
自动下载 Reddit 表情包到 Google Drive,含重复检测和 Telegram 提醒
自动下载 Reddit 表情包到 Google Drive,包含重复检测和 Telegram 提醒
If
Set
Code
+10
20 节点Vitorio Magalhães
文件管理
WordPress博客自动化专业版(深度研究)v2.1市场
使用GPT-4o、Perplexity AI和多语言支持自动化SEO优化的博客创建
If
Set
Xml
+27
125 节点Daniel Ng
内容创作
内容生成器 v3
AI驱动博客自动化:使用GPT-4生成并发布SEO文章至WordPress和Twitter
If
Set
Code
+25
144 节点Jay Emp0
内容创作
Google Meet AI助手
使用Google Meet、AssemblyAI和Claude AI自动化会议摘要与行动项
If
Set
Code
+12
25 节点Dominic
内容创作
LinkedIn和X病毒内容自动引擎
使用AI生成和发布自动创建LinkedIn和X的病毒内容
If
Set
Wait
+26
156 节点Diptamoy Barman
内容创作
我的智能体竞技场社区竞赛
使用Qdrant、Mistral OCR和GPT-4构建基于RAG的问答系统
Set
Code
Wait
+19
41 节点Davide
内容创作