Last active
August 29, 2015 14:27
-
-
Save dented/fb038b8e39503134b7c8 to your computer and use it in GitHub Desktop.
Move a tree of files in a single folder to a new list of folders with individual files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'fileutils' | |
| directory = './files' | |
| new_directory = './new' | |
| files = Dir["#{directory}/*"] | |
| Dir.mkdir(new_directory) if !Dir.exists?(new_directory) | |
| files.each do |file| | |
| file_name = File.basename(file) | |
| directory_name = File.basename(file_name, File.extname(file_name)) | |
| directory_path = "#{new_directory}/#{directory_name}" | |
| Dir.mkdir(directory_path) if !Dir.exists?(directory_path) | |
| FileUtils.mv(file, "#{directory_path}/#{file_name}") | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment