Created
April 15, 2011 09:31
-
-
Save morygonzalez/921460 to your computer and use it in GitHub Desktop.
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
require "fileutils" | |
dir = Dir::entries(Dir::pwd) | |
dir.each do |d| | |
unless /(^\.|#{__FILE__})/ =~ d | |
f = File::stat(d) | |
puts "#{d} is #{(Time.now - f.mtime).div(24*60*60)} days old." | |
puts "Would you like to remove this file/directory? (y/n)" | |
answer = gets.chomp | |
if answer == "y" | |
if FileTest.file?(d) | |
File::delete(d) | |
else | |
dirlist = Dir::glob(d + "**/").sort { | |
|a,b| b.split('/').size <=> a.split('/').size | |
} | |
dirlist.each {|d| | |
Dir::foreach(d) {|f| | |
FileUtils.rm_rf(d+f) unless (/\.+$/ =~ f) | |
} | |
Dir::rmdir(d) | |
} | |
end | |
else | |
next | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment