Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move files and folders using google drive API?

I am trying to use Google drive API to carry out simple tasks like

  1. Moving files across folders.
  2. List item

Moving folders.

As far as I could find Google drive API does not provide a way to move files across folders.

With /parent and /children API parent folder of a file can be specified but it does not work for a folder. Moreover the parent attribute associated with a file does not move it under that folder. It just associates a parent attribute with the file(which is not at all useful for my case)

like image 252
NitinJ Avatar asked Oct 08 '12 09:10

NitinJ


People also ask

How do I mass move files in Google Drive?

If you have multiple files to move in Google Drive, you can: If the files are displayed orderly, you can click the first one, then press Shift on your keyboard and click the last one. In this way, all files from the first one to the last one will be selected. Next, you can right-click to choose Move to.

How do I move an entire folder in Google Drive?

Right-click the item you want to move. Click Move to. Select or create a folder. Click Move.

How do I create a Google Drive folder in Google Drive API?

To create a file in a folder, use the files. create method and specify the folder ID in the parents property of the file. The following code snippet shows how to create a file in a specific folder using a client library: Note: If you're using the older Drive API v2, use the files.


2 Answers

Drive API V3 has this:

Moving files between folders

To add or remove parents for an existing file, use the addParents and removeParents query parameters on the files.update method.

Both parameters may be used to move a file from one folder to another: https://developers.google.com/drive/v3/web/folder#inserting_a_file_in_a_folder

like image 160
intotecho Avatar answered Oct 10 '22 20:10

intotecho


To move FILE-A from FOLDER-1 to FOLDER-2, you can use the delete and add calls at https://developers.google.com/drive/v2/reference/parents to remove FOLDER-1 as a parent and add FOLDER-2.

You can also do a Patch on the file with the updated parents array.

like image 12
pinoyyid Avatar answered Oct 10 '22 20:10

pinoyyid