Skip to content

Instantly share code, notes, and snippets.

@kyamaguchi
Last active August 2, 2017 15:50
Show Gist options
  • Save kyamaguchi/190d18769dab70dc44e9c25e90575b35 to your computer and use it in GitHub Desktop.
Save kyamaguchi/190d18769dab70dc44e9c25e90575b35 to your computer and use it in GitHub Desktop.
List files on Dropbox with Ruby
require 'dropbox_api'
require 'byebug'
client = DropboxApi::Client.new('your_access_token')
start_dir = '/broken_files'
def find_files(client, f)
if f.to_hash[".tag"] == "folder"
puts "[FOLDER] #{f.path_lower}"
sleep 5
result = begin
client.list_folder(f.path_lower)
rescue DropboxApi::Errors::TooManyRequestsError => e
puts e.message
sleep 60
retry
end
byebug if result.has_more?
result.entries.map{|f| find_files(client, f) }
elsif f.to_hash[".tag"] == "file"
puts "[FILE] #{f.path_lower}"
[f]
else
raise("Unknown type: #{f.to_hash}")
end.flatten
end
all_entries = client.list_folder(start_dir).entries.map{|f| find_files(client, f) }.flatten;nil
all_entries.size
# Select files which had changed after 2017-08-01
target_files = all_entries.select{|f| f.server_modified > Time.utc(2017,8,1) };nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment