Skip to content

Instantly share code, notes, and snippets.

@Zyber17
Created January 5, 2014 04:08
Show Gist options
  • Save Zyber17/8264230 to your computer and use it in GitHub Desktop.
Save Zyber17/8264230 to your computer and use it in GitHub Desktop.
A [Maid](https://github.com/benjaminoakes/maid) rule for 'moving' folders and their files. (Only works if there are no subdirectories.)
rule 'Move folders from one directory to another' do
folder_destination = '[the path of the directory to where we want the folder moved]'
if File.directory?(folder_destination) #Let's make sure that the directory we want to move the folder to exists
dir('[the direcotry where we are getting the folder from]').each do |folder| #Let's grab all the potential folders
if File.directory?(folder) #Let's check and see if this item is a folder
file_destination = folder_destination + File.basename(folder) #Let's get the path to the folder we're about to create
mkdir(file_destination) #We need to make the 'moved' folder where we're going to put the files from the original folder
move(dir("#{folder}/*"), file_destination) #Now we can move the files
trash(folder) #Finally, let's trash the original folder
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment