Comments (4)
@jayofelony so, what exactly doesn't work in this case?
it should be possible to get a ID by its name and it should be possible to create a new directory. So the approach makes sense overall. We just need to see where exactly it breaks.
from pydrive2.
My bad, I am searching in the drive for a folder that does not exist. I edited the post a little with errors thrown.
SO basiscally I know the folder does not exist, so I need it to be created. Because a user can change the backup folder if they want.
from pydrive2.
Could you check this example https://github.com/iterative/PyDrive2/blob/main/examples/Upload-and-autoconvert-to-Google-Drive-Format-Example/upload.py#L38 and try to "play" with a query a bit? I think you might need to pass something like this:
query = {'q': f"title = '{filename}' and mimeType='{mimetype}'"}
Check also this doc. And also I would try to run it first on the online sandbox here.
from pydrive2.
Right, I have come to a succesful edit.
def get_folder_id_by_name(self, drive, folder_name):
file_list = drive.ListFile({'q': "mimeType='application/vnd.google-apps.folder' and trashed=false"}).GetList()
for file in file_list:
if file['title'] == folder_name:
return file['id']
return None
if not self.backup:
# Use self.options['backup_folder'] as the folder ID where backups are stored
backup_folder_id = self.get_folder_id_by_name(self.drive, self.options['backup_folder'])
if backup_folder_id is None:
# If the folder doesn't exist, create it
folder = self.drive.CreateFile(
{'title': self.options['backup_folder'], 'mimeType': 'application/vnd.google-apps.folder'})
folder.Upload()
backup_folder_id = folder['id']
logging.info(f"[gDriveSync] Created folder '{self.options['backup_folder']}' with ID: {backup_folder_id}")
# Continue with the rest of the code using backup_folder_id
file_list = self.drive.ListFile({'q': f"'{backup_folder_id}' in parents and mimeType = 'application/vnd.google-apps.folder' and trashed=false"}).GetList()
from pydrive2.
Related Issues (20)
- How do I write to specific tab? HOT 1
- Missing 1.17.1 release? HOT 1
- auth: LocalWebserverAuth: fail if in non-interactive mode
- ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:2427) HOT 2
- Review and fix issues with find
- Create Succesfull Authentication using Google OAuth client ID for a remote server accessible via SSH in a local machine HOT 1
- AssertionError on using fsspec with service account HOT 1
- [Q]Set Disable Download HOT 1
- Would you be interested to add type hints?
- pyopenssl is a dependency, but it does not seem to be used
- httplib2 is a direct dependency but is not added as one
- SaveCredentialsFile() does not store anything
- CommandLineAuth Generate Wrong Link HOT 1
- colab TypeError: GoogleAuth.LocalWebserverAuth() takes from 1 to 3 positional arguments but 5 were given HOT 1
- Can't upload file with my service account HOT 1
- fs.makedirs() fails unless you put a file in the folder (shared drive)
- Delete/Trash files when authenticating with a Service Account HOT 2
- Error in pull/push "The query is too complex." HOT 7
- Regsister fsspec interface with fsspec HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pydrive2.