Skip to content

Commit 9854108

Browse files
committed
made changes suggested by aiguofer in PR aiguofer#48
1 parent e762ee5 commit 9854108

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

gspread_pandas/client.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def create_folder(self, path, parents=True):
403403
self.refresh_directories()
404404
return parent
405405

406-
def move_file(self, file_id, path, create=False):
406+
def move_file(self, file_id, path=None, folder_id=None, create=False):
407407
"""
408408
Move a file to the given path.
409409
@@ -414,22 +414,29 @@ def move_file(self, file_id, path, create=False):
414414
path : str
415415
folder path. A path starting with `/` will use your drive, for shared drives
416416
the path will start with `<Shared Drive Name>/` (no leading /)
417+
(Default value = None)
418+
folder_id: str
419+
folder id to move file to. (Default value = None)
417420
create : bool
418421
whether to create any missing folders (Default value = False)
419422
420423
Returns
421424
-------
422425
"""
423-
if path == "/":
424-
folder_id = "root"
425-
else:
426-
parent, missing = folders_to_create(path, self._get_dirs(False))
427-
if missing:
428-
if not create:
429-
raise Exception("Folder does not exist")
426+
if path is None and folder_id is None:
427+
raise Exception("Either path or folder_id is required")
428+
429+
if path:
430+
if path == "/":
431+
folder_id = "root"
432+
else:
433+
parent, missing = folders_to_create(path, self._get_dirs(False))
434+
if missing:
435+
if not create:
436+
raise Exception("Folder does not exist")
430437

431-
parent = self.create_folder(path)
432-
folder_id = parent["id"]
438+
parent = self.create_folder(path)
439+
folder_id = parent["id"]
433440

434441
old_parents = self._drive_request(
435442
"get", file_id, params={"fields": "parents"}

gspread_pandas/spread.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,19 +1012,24 @@ def list_permissions(self):
10121012
"""
10131013
return self.client.list_permissions(self.spread.id)
10141014

1015-
def move(self, path="/", create=True):
1015+
def move(self, path="/", folder_id=None, create=True):
10161016
"""
1017-
Move the current spreadsheet to the specified path in your Google drive. If the
1018-
file is not currently in you drive, it will be added.
1017+
Move the current spreadsheet to the specified path or folder_id in your
1018+
Google drive. If the file is not currently in you drive, it will be
1019+
added.
10191020
10201021
Parameters
10211022
----------
10221023
path : str
10231024
folder path (Default value = "/")
1025+
folder_id: str
1026+
folder id (Default value = None)
10241027
create : bool
10251028
if true, create folders as needed (Default value = True)
10261029
10271030
Returns
10281031
-------
10291032
"""
1030-
self.client.move_file(self.spread.id, path, create)
1033+
if folder_id:
1034+
path = None
1035+
self.client.move_file(self.spread.id, path, folder_id, create)

0 commit comments

Comments
 (0)