Skip to content

Instantly share code, notes, and snippets.

@nacookan
Created March 18, 2014 05:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nacookan/9613947 to your computer and use it in GitHub Desktop.
Save nacookan/9613947 to your computer and use it in GitHub Desktop.
今日の日付で自動的にフォルダを作る
#! /usr/bin/env ruby
if ARGV[0] != nil
if File.exists?(ARGV[0])
if FileTest.directory?(ARGV[0])
path = ARGV[0]
else
abort ARGV[0] + " is not a directory."
end
else
abort ARGV[0] + " not found."
end
else
path = Dir.pwd
end
date_format = "%Y%m%d"
yesterday = (Time.now - 60 * 60 * 24).strftime(date_format)
(1..99).each do |i|
dir = File.join(path, sprintf("%s%02d", yesterday, i))
if File.exists?(dir)
if Dir.entries(dir).join == "..."
Dir.rmdir(dir)
puts dir + " : exists, empty -> removed"
end
end
end
today = Time.now.strftime(date_format)
(1..99).each do |i|
dir = File.join(path, sprintf("%s%02d", today, i))
if File.exists?(dir)
if Dir.entries(dir).join == "..."
puts dir + " : exists, empty"
exit
else
puts dir + " : exists, not-empty"
next
end
else
Dir.mkdir(dir)
puts dir + " : not-exists -> created"
exit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment