使用 pydrive 或 google 驱动器 api 将文件复制到 google 驱动器
copy file in google drive using pydrive or google drive api
function copyFolderContents_(source, target) {
// Iterate files in source folder
const filesIterator = source.getFiles()
while (filesIterator.hasNext()) {
const file = filesIterator.next()
// Make a copy of the file keeping the same name
file.makeCopy(file.getName(), target) // need to find python function replacing THIS LINE!!!!!!!!!!!!!!!!!!
}
}
const toCopy = DriveApp.getFolderById('')
const copyInto = DriveApp.getFolderById('')
const newFolder = copyInto.createFolder(toCopy.getName())
copyFolderContents_(toCopy, newFolder)
我试图将此应用程序脚本重写为 python,这只会将文件而不是文件夹复制到另一个位置
是否有任何 pydrive 或 vanilla HTTP restful API 可以替代 file.makeCopy(file.getName(), target)
?
访问 ref 后,似乎这个 restful API 没有我可以指定的目标。
Files:copy is the same as the destination in makeCopy(name, destination)请求体中的parent[]
参数。
示例:
这里我有一个名为 68759008 的文件夹,其中包含示例文档:
这是我要复制示例文档的目标文件夹。
使用 API 资源管理器:
请求参数:
在请求参数中,我只插入了示例文档的文件ID
请求正文:
{
"parents": [
"Insert Destination folder ID here"
],
"name": "68759008_TEST_DOC_COPY"
}
响应:
输出:
获取父 ID 或目标文件夹 ID 有两种选择:
- 您可以转到目标文件夹并复制
https://drive.google.com/drive/folders/
之后的字符串
- 使用Files:list,找到文件名,
mimeType
应该是application/vnd.google-apps.folder
文件:列表示例:
function copyFolderContents_(source, target) {
// Iterate files in source folder
const filesIterator = source.getFiles()
while (filesIterator.hasNext()) {
const file = filesIterator.next()
// Make a copy of the file keeping the same name
file.makeCopy(file.getName(), target) // need to find python function replacing THIS LINE!!!!!!!!!!!!!!!!!!
}
}
const toCopy = DriveApp.getFolderById('')
const copyInto = DriveApp.getFolderById('')
const newFolder = copyInto.createFolder(toCopy.getName())
copyFolderContents_(toCopy, newFolder)
我试图将此应用程序脚本重写为 python,这只会将文件而不是文件夹复制到另一个位置
是否有任何 pydrive 或 vanilla HTTP restful API 可以替代 file.makeCopy(file.getName(), target)
?
访问 ref 后,似乎这个 restful API 没有我可以指定的目标。
Files:copy is the same as the destination in makeCopy(name, destination)请求体中的parent[]
参数。
示例:
这里我有一个名为 68759008 的文件夹,其中包含示例文档:
这是我要复制示例文档的目标文件夹。
使用 API 资源管理器:
请求参数:
在请求参数中,我只插入了示例文档的文件ID
请求正文:
{
"parents": [
"Insert Destination folder ID here"
],
"name": "68759008_TEST_DOC_COPY"
}
响应:
输出:
获取父 ID 或目标文件夹 ID 有两种选择:
- 您可以转到目标文件夹并复制
https://drive.google.com/drive/folders/
之后的字符串
- 使用Files:list,找到文件名,
mimeType
应该是application/vnd.google-apps.folder
文件:列表示例: