Created
December 14, 2012 03:38
-
-
Save JGallardo/4282549 to your computer and use it in GitHub Desktop.
Ruby script to check for orphan files on a web server.
This file contains hidden or 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
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