Skip to content

Instantly share code, notes, and snippets.

@jfouse
Last active August 27, 2015 15:11
Show Gist options
  • Save jfouse/cb8890b727df470844bc to your computer and use it in GitHub Desktop.
Save jfouse/cb8890b727df470844bc to your computer and use it in GitHub Desktop.
Ruby file/folder shredding
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