Created
June 16, 2015 18:40
-
-
Save cmar/abc9f1a708cd77968af8 to your computer and use it in GitHub Desktop.
Example Rakefile for managing photos
This file contains 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
# if you have a directory of files that look like: | |
# 2015-03-21 11.23.39.jpg | |
# 2015-04-15 09.55.20.jpg | |
# 2015-03-21 11.23.42.jpg | |
# 2015-05-12 13.14.59.png | |
# | |
# this Rakefile will move all the files into subdirectories for year/month | |
task :default do |task| | |
file_list = FileList['*.jpg', '*.png'] | |
file_list.each do |file| | |
year = file[/^\d{4}/] | |
month = file[/(?<=^\d{4}-)\d{2}/] | |
directory = File.join year, month | |
mkdir_p directory | |
mv file, directory | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment