Skip to content

Instantly share code, notes, and snippets.

@vargheseraphy
Created January 30, 2015 07:11
Show Gist options
  • Save vargheseraphy/7f3dfc68d5ed3e16fa35 to your computer and use it in GitHub Desktop.
Save vargheseraphy/7f3dfc68d5ed3e16fa35 to your computer and use it in GitHub Desktop.
Organize Files in Folders
require 'fileutils'
(0..99).each do |p|
p_name = 'klhcc' + (p * 1000).to_s.rjust(5, '00000')
FileUtils.mkdir_p (0..99).map{ |c| "#{p_name}/klhcc" + (p * 1000 + c * 100).to_s.rjust(5, '00000') }
end
Dir.glob("*.md") do |file|
filename = File.basename(file, '.md')
pf = 'klhcc' + "#{filename.chop.chop.chop}000".rjust(5, '00000')
cf = 'klhcc' + "#{filename.chop.chop}00".rjust(5, '00000')
FileUtils.mv(file, "#{pf}/#{cf}/#{filename}.md")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment