Last active
August 27, 2015 15:11
-
-
Save jfouse/cb8890b727df470844bc to your computer and use it in GitHub Desktop.
Ruby file/folder shredding
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
def cleanup(target) | |
if FileTest.file?(target) | |
shred(target) | |
else | |
Find.find(File.absolute_path(target)) do |thing| | |
if FileTest.file?(thing) | |
shred(thing) | |
end | |
end | |
end | |
FileUtils.remove_entry_secure target | |
end | |
def shred(target) | |
size = File.size(target) | |
7.times do | |
File.open(target, 'wb') do |f| | |
byte = Random.rand(0xff) | |
size.times { f.print(byte.chr) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment