Skip to content

Instantly share code, notes, and snippets.

@valachi
Created October 10, 2012 14:45
Show Gist options
  • Select an option

  • Save valachi/3866079 to your computer and use it in GitHub Desktop.

Select an option

Save valachi/3866079 to your computer and use it in GitHub Desktop.
require 'fileutils'
new_path = '/home/valachi/ruby/new_uploads'
old_path = '/home/valachi/ruby/uploads'
[new_path, old_path].each do |path|
Dir.mkdir(path) unless Dir.exists?(path)
23.times do |i|
Dir.mkdir("#{path}/#{i}") unless File.exists?("#{path}/#{i}")
end
end
Dir.foreach(new_path) do |folder|
next if folder == '.' || folder == '..'
new_file = File.join(new_path, "/#{folder}/#{folder}.txt")
unless File.exists?(new_file)
File.open(new_file, 'w') {}
end
end
folders = []
Dir.foreach(old_path) do |folder|
next if folder == '.' || folder == '..'
folders << folder
FileUtils.rm_rf(old_path + "/#{folder}")
end
slice_value = (folders.size.to_f / 4).round
folders.each_slice(slice_value) do |folders|
folders.each do |folder|
`ln -s "#{new_path}/#{folder}" "#{old_path}/#{folder}"`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment