Skip to content

Instantly share code, notes, and snippets.

@cburnette
Last active April 27, 2016 08:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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' #gem install 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: "YOUR_CLIENT_ID",
client_secret: "YOUR_CLIENT_SECRET",
access_token: "YOUR_DEV_ACCESS_TOKEN"
})
@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}"
puts f.modified_at < MODIFIED_AT_CUTOFF ? red(output) : output
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