Created
March 5, 2016 14:05
-
-
Save valpackett/274717f137c22eecd3d5 to your computer and use it in GitHub Desktop.
Convert Sweetroll entires' file names to new, date-based format
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
%w(date json).each { |m| require m } | |
Dir[File.join ARGV.first, "**/*.json"].each do |path| | |
fname = File.basename(path) | |
next if (fname =~ /^\d+-.*/).nil? | |
pub = (JSON.parse(File.read(path))["properties"] || {})["published"] || [] | |
next if pub.empty? | |
newpath = File.join File.dirname(path), fname.gsub(/^\d+/, DateTime.parse(pub.first).strftime("%s")) | |
puts "#{path} => #{newpath}" | |
File.rename path, newpath | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment