Hi,
I was trying to download zip files within a folder from my dropbox.
For example, there are 7z files named 0.7z, 1.7z, ... 5.7z under folder name 'extra'.
I could download the 7z files via API, but the size of each 7z file turned out zero although they are around 11GB each.
Other text files under the same folder are downloaded correctly.
Could you let me know how I can download the zip files correctly?
Here is the Python 3 code that I am using:
import dropbox
def process_folder_entries(current_state, entries):
for entry in entries:
if isinstance(entry, dropbox.files.FileMetadata):
current_state[entry.path_lower] = entry
elif isinstance(entry, dropbox.files.DeletedMetadata):
current_state.pop(entry.path_lower, None) # ignore KeyError if missing
return current_state
# Initializing Dropbox API
dbx = dropbox.Dropbox("token")
# Scanning for files
path = r"/download"
result = dbx.files_list_folder(folder_name)
files = process_folder_entries({}, result.entries)
# check for and collect any additional entries
while result.has_more:
result = dbx.files_list_folder_continue(result.cursor)
files = process_folder_entries(files, result.entries)
# define the download location.
directory = directoryname
for entry in files.values():
new_file_path = directory + entry.name
# download the file, returns the File Metadata and File Content.
#file_metadata, file_content = dbx.files_download(entry.path_lower)
file_metadata, res = dbx.files_download(entry.path_lower)
try:
# write the file to the directory
with open(new_file_path,'w') as new_file:
new_file.write(res.content)
except:
continue