Skip to content

Instantly share code, notes, and snippets.

@JGallardo
Created December 14, 2012 03:38
Show Gist options
  • Save JGallardo/4282549 to your computer and use it in GitHub Desktop.
Save JGallardo/4282549 to your computer and use it in GitHub Desktop.
Ruby script to check for orphan files on a web server.
links = Array.new
orphans = Array.new
dir_array = [Dir.getwd]
unless File.readable?("links.txt")
puts "File is not readable."
exit
end
File.open('links.txt', 'rb') do |lv|
lv.each_line do |line|
links << line.chomp
end
end
begin
p = dir_array.shfit
Dir.chdir(p)
Dir.foreach(p) do |filename|
next if filename == '.' or filename == '..'
if !File::directory?(filename)
orphans << p + File::SEPARATOR + filename
else
dir_array << p + File::SEPARATOR + filename
end
end
end
end while !dir_array.empty?
orphans -= links
File.open("orphans.txt", "wb") do |o|
o.puts orphans
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment