I am trying to use Google drive API to carry out simple tasks like
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)
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.
Right-click the item you want to move. Click Move to. Select or create a folder. Click Move.
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.
Drive API V3 has this:
Moving files between folders
To add or remove parents for an existing file, use the
addParents
andremoveParents
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With