有一种更简单的方法更有意义。
安装 Python 和 Gam 后,您可以运行一个脚本,该脚本使用来自 google 驱动器的文件 id 在 csv 文件中导出列表中的所有文档。安装 python 和 gam 后,您需要安装一些模块才能使脚本正常工作。当您运行脚本时,可以搜索错误代码以查看需要在 Python 中安装的内容。此外,您还需要创建一个 api 凭据服务帐户,并在两个地方的脚本中将该帐户名称替换为该帐户名称。
以管理员身份使用以下命令运行 cmd,脚本名称为 script.py。
"C:\Users\dcahoon\AppData\Local\Programs\Python\Python38\python.exe C:\GAM\SCRIPT.PY
**脚本开始
import os
import subprocess
from csv import writer
from csv import reader
# path to googleidlist.csv
csvfile = 'c:\\GAM\\googleidlist.csv'
destination = 'c:\\GAM\\OUTPUT\\' #Destination for downloaded documents
# Open the input_file in read mode and output_file in write mode
with open(csvfile, 'r') as read_obj, \
open('output_1.txt', 'w', newline='') as write_obj:
# Create a csv.reader object from the input file object
csv_reader = reader(read_obj)
# Create a csv.writer object from the output file object
csv_writer = writer(write_obj)
# Read each row of the input csv file as list
for row in csv_reader:
file_id = row[0]
outcome = subprocess.Popen(['gam', 'user', 'googleserviceaccountname', 'get', 'drivefile', 'id', file_id, 'targetfolder',destination], stdout=subprocess.PIPE)
# os.system("gam user david.bruinsma@colonialmed.com show fileinfo "+ file_id + "name")
filename = subprocess.Popen(['gam', 'user', 'googleserviceaccountname', 'show', 'fileinfo', file_id, 'name' ], stdout=subprocess.PIPE)
output = outcome.stdout.readline()
file_name = filename.stdout.readline()
print(output)
# Append the default text in the row / list
# row.append(filename)
row.append(output)
row.append(file_name)
row.append(file_id)
# Add the updated row / list to the output file
csv_writer.writerow(row)
**脚本结束