I've copied a large number of .jpg images from my Google Drive to Google Colab per Google Colab: how to read data from my google drive?:
local_download_path = os.path.expanduser('~/data')
try:
os.makedirs(local_download_path)
except: pass
# 2. Auto-iterate using the query syntax
# https://developers.google.com/drive/v2/web/search-parameters
file_list = drive.ListFile(
{'q': "'1SooKSw8M4ACbznKjnNrYvJ5wxuqJ-YCk' in parents"}).GetList()
for f in file_list:
# 3. Create & download by id.
print('title: %s, id: %s' % (f['title'], f['id']))
fname = os.path.join(local_download_path, f['title'])
print('downloading to {}'.format(fname))
f_ = drive.CreateFile({'id': f['id']})
f_.GetContentFile(fname)
This completed, so all the image files should be in a data
folder. How do I actually access these files now? I'd like to loop through all files that are of type .jpg in the data
folder.
One alternative would be to use the already implemented os library.
# Just needed in case you'd like to append it to an array
data = []
for filename in os.listdir(local_download_path):
if filename.endswith("jpg"):
# Your code comes here such as
print(filename)
data.append(filename)
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