Skip to content

Instantly share code, notes, and snippets.

@cburnette
Last active April 27, 2016 08:18
Show Gist options
  • Save cburnette/0ba987a762077bef9969 to your computer and use it in GitHub Desktop.
Save cburnette/0ba987a762077bef9969 to your computer and use it in GitHub Desktop.
This code snippet will connect to a Box account and loop through all the folders recursively, printing out all the filenames, while highlighting in red files that have a modified_at date older than the specified threshold. In other words, it highlights files that haven't been changed in a while.
require 'ruby-box'
require 'term/ansicolor' #gem install term-ansicolor
include Term::ANSIColor
MODIFIED_AT_CUTOFF = Time.new(2013,7,1)
session = RubyBox::Session.new({
client_id: "6nbxyrx54ikg9j8rb444l8_not_real",
client_secret: "ugVH49V8OsOnPkORHduBBql5A_not_real",
access_token: "Xb1zHzCZM4jcs96d6Dl4kzNe_not_real"
})
@client = RubyBox::Client.new(session)
def load_folder(folder, path_prefix="/")
path = "#{path_prefix}#{folder.name}"
puts path
files = folder.files(nil,1000,0,['name','modified_at'])
files.each do |f|
output = "--> #{f.name}"
if f.modified_at < MODIFIED_AT_CUTOFF
puts red(output)
else
puts output
end
end
subFolders = folder.folders
subFolders.each do |f|
load_folder f, "#{path}/"
end
end
load_folder @client.root_folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment