2222from googleapiclient .errors import HttpError
2323
2424
25- def move_file_to_folder (real_file_id , real_folder_id ):
25+ def move_file_to_folder (file_id , folder_id ):
2626 """Move specified file to the specified folder.
2727 Args:
28- real_file_id : Id of the file to move.
29- real_folder_id : Id of the folder
28+ file_id : Id of the file to move.
29+ folder_id : Id of the folder
3030 Print: An object containing the new parent folder and other meta data
31+ Returns : Parent Ids for the file
3132
3233 Load pre-authorized user credentials from the environment.
3334 TODO(developer) - See https://developers.google.com/identity
@@ -39,9 +40,6 @@ def move_file_to_folder(real_file_id, real_folder_id):
3940 # call drive api client
4041 service = build ('drive' , 'v2' , credentials = creds )
4142
42- file_id = real_file_id
43- folder_id = real_folder_id
44-
4543 # Retrieve the existing parents to remove
4644 # pylint: disable=maybe-no-member
4745 file = service .files ().get (fileId = file_id , fields = 'parents' ).execute ()
@@ -52,16 +50,16 @@ def move_file_to_folder(real_file_id, real_folder_id):
5250 removeParents = previous_parents ,
5351 fields = 'id, parents' ).execute ()
5452 new_parent_folder_id = [parent ["id" ] for parent in file .get ('parents' )]
55- print (F'file with ID : { file .get ("id" )} has moved to folder : '
53+ print (F'file with ID : { file .get ("id" )} moved to folder : '
5654 F'{ new_parent_folder_id } ' )
55+ return [parent ["id" ] for parent in file .get ('parents' )]
5756
5857 except HttpError as error :
5958 print (F'An error occurred: { error } ' )
60-
61- return [parent ["id" ] for parent in file .get ('parents' )]
59+ return None
6260
6361
6462if __name__ == '__main__' :
65- move_file_to_folder (real_file_id = '14fesChjgzDA7lUu9ZeGqXOuXMPgaVkxS' ,
66- real_folder_id = '1KzT9gjq-AHfciwNzKjh7nUd6prrQOA4' )
63+ move_file_to_folder (file_id = '14fesChjgzDA7lUu9ZeGqXOuXMPgaVkxS' ,
64+ folder_id = '1KzT9gjq-AHfciwNzKjh7nUd6prrQOA4' )
6765# [END drive_move_file_to_folder]
0 commit comments