Skip to content

Instantly share code, notes, and snippets.

@cmar
Created June 16, 2015 18:40
Show Gist options
  • Save cmar/abc9f1a708cd77968af8 to your computer and use it in GitHub Desktop.
Save cmar/abc9f1a708cd77968af8 to your computer and use it in GitHub Desktop.
Example Rakefile for managing photos
# 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