Found it here. 당신은 그냥 파일 및 폴더 ID를 검색 한 후 업데이트 방법을 사용해야합니다. 당신이 이전 폴더 (들)에있는 파일의 복사본을 남겨하려는 경우 remove_parents 매개 변수를 제외 할 수
file_id = '1sTWaJ_j7PkjzaBWtNc3IzovK5hQf21FbOw9yLeeLPNQ'
folder_id = '0BwwA4oUTeiV1TGRPeTVjaWRDY1E'
# Retrieve the existing parents to remove
file = drive_service.files().get(fileId=file_id,
fields='parents').execute();
previous_parents = ",".join(file.get('parents'))
# Move the file to the new folder
file = drive_service.files().update(fileId=file_id,
addParents=folder_id,
removeParents=previous_parents,
fields='id, parents').execute()
볼 것이다 그래서 내 원래의 기능 (내 기본 도우미 함수 _getFileId 및 _getFolderId을 포함하지 않은 참고) 예 :
def move_file(service, filename, init_drive_path, drive_path, copy=False):
"""Moves a file in Google Drive from one location to another.
service: Drive API service instance.
'filename' (string): file path on local machine, or a bytestream
to use as a file.
'init_drive_path' (string): the file path the file was initially in on Google
Drive (in <folder>/<folder>/<folder> format).
'drive_path' (string): the file path to move the file in on Google
Drive (in <folder>/<folder>/<folder> format).
'copy' (boolean): file should be saved in both locations
Returns nothing.
"""
file_id = _getFileId(service, filename, init_drive_path)
folder_id = _getFolderId(service, drive_path)
if not file_id or not folder_id:
raise Exception('Did not find file specefied: {}/{}'.format(init_drive_path, filename))
file = service.files().get(fileId=file_id,
fields='parents').execute()
previous_parents = ",".join(file.get('parents'))
if copy:
previous_parents = ''
file = service.files().update(fileId=file_id,
addParents=folder_id,
removeParents=previous_parents,
fields='id, parents').execute()