Skip to content

Instantly share code, notes, and snippets.

@edulan
Created April 10, 2010 15:28
Show Gist options
  • Save edulan/362070 to your computer and use it in GitHub Desktop.
Save edulan/362070 to your computer and use it in GitHub Desktop.
# Make balanced image directories to improve file system search
#
# Example:
#
# make_balanced_dirs(2, 4)
# ac3294f2b0174ee1.jpg -> ac329/4f2b/ac3294f2b0174ee1.jpg
#
def make_balanced_dirs levels, length
Dir.glob("*.jpg").collect do |f|
f.split('.')[0].gsub(/[a-f0-9]{lenght}/) { |m| File.join(m,'') }[0..(levels*length)+1].concat(f)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment