Skip to content

Instantly share code, notes, and snippets.

@techno-tanoC
Created April 9, 2018 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techno-tanoC/0a8855eca646a4b668e69b2543a7b509 to your computer and use it in GitHub Desktop.
Save techno-tanoC/0a8855eca646a4b668e69b2543a7b509 to your computer and use it in GitHub Desktop.
require 'fileutils'
def blobs(path)
Dir.glob(path)
end
def files(files)
files.select {|f| File.file?(f) }
end
def dirs(files)
files.select {|f| File.directory?(f) }
end
def find(dirs, file)
dirs.find do |dir|
d = File.basename(dir)
file.include?(d)
end
end
def main(path)
bs = blobs(File.join(path, '*'))
fs = files(bs)
ds = dirs(bs)
fs.each do |f|
if dir = find(ds, File.basename(f))
puts "move: #{f} to #{dir}"
FileUtils.move(f, dir)
end
end
end
if path = ARGV[0]
main(path)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment