Skip to content

Instantly share code, notes, and snippets.

@morygonzalez
Created April 15, 2011 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morygonzalez/921460 to your computer and use it in GitHub Desktop.
Save morygonzalez/921460 to your computer and use it in GitHub Desktop.
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