22
22
from googleapiclient .errors import HttpError
23
23
24
24
25
- def move_file_to_folder (real_file_id , real_folder_id ):
25
+ def move_file_to_folder (file_id , folder_id ):
26
26
"""Move specified file to the specified folder.
27
27
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
30
30
Print: An object containing the new parent folder and other meta data
31
+ Returns : Parent Ids for the file
31
32
32
33
Load pre-authorized user credentials from the environment.
33
34
TODO(developer) - See https://developers.google.com/identity
@@ -39,9 +40,6 @@ def move_file_to_folder(real_file_id, real_folder_id):
39
40
# call drive api client
40
41
service = build ('drive' , 'v2' , credentials = creds )
41
42
42
- file_id = real_file_id
43
- folder_id = real_folder_id
44
-
45
43
# Retrieve the existing parents to remove
46
44
# pylint: disable=maybe-no-member
47
45
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):
52
50
removeParents = previous_parents ,
53
51
fields = 'id, parents' ).execute ()
54
52
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 : '
56
54
F'{ new_parent_folder_id } ' )
55
+ return [parent ["id" ] for parent in file .get ('parents' )]
57
56
58
57
except HttpError as error :
59
58
print (F'An error occurred: { error } ' )
60
-
61
- return [parent ["id" ] for parent in file .get ('parents' )]
59
+ return None
62
60
63
61
64
62
if __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' )
67
65
# [END drive_move_file_to_folder]
0 commit comments