Very simple question. How can I copy a folder with the Google Drive API?
It looks like the file/copy API endpoint doesn't work with folders (though this limitation is not clearly indicated in the documentation).
Of course I could add a second parent to the file, but obviously that's not a solution as most of the time a folder copy is done to do something with it without modifying the original.
So how can I do that? Any idea?
If you have the Google Drive app installed on your computer, you can copy a folder in Google Drive the same way you'd copy any other folder of files. Right-click on the folder, click Copy, then go wherever you want to copy the folder, right-click again, and click Paste.
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.
'copy' wouldn't make much sense on a folder. The purpose of copy is to create a second file with the same media content as the first. Since a folder has no media content, 'copy' doesn't really apply.
To answer the question, we need to understand your use case a little. Take a *nix paradigm, "cp -R folder1 folder2" is recursively duplicating all of the files. If that is your use case, you'll need to manually recurse down the tree. If you want the same files to appear in two places, (ie. "ln -s folder1 folder2") then that is done by adding a second parent.
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