Oops forget the very begin line ...

require 'pathname'


On 8/3/05, David Tran <email55555 / gmail.com> wrote:
> FILES_NAME = 'files.txt'          # files.txt will content all files name
> OLD_FILES_NAME = 'old_files.txt'  # backup for current files.txt
> 
> def get_files( pathname )
>   result = []
>   pathname.children.each { |e|
>     result << e.to_s
>     result += get_files(e) if e.directory?
>   }
>   result
> end
> 
> old_files = []
> begin
>   old_files = IO.readlines(FILES_NAME).map { |e| e.chomp }
>   File.rename(FILES_NAME, OLD_FILES_NAME)
> rescue
> end
> 
> new_files = get_files(Pathname.new(File.expand_path('.'))).sort
> open(FILES_NAME, 'w') { |f| new_files.each { |e| f.puts(e) } }
> 
> extra = new_files - old_files
> removed = old_files - new_files
> 
> if !extra.empty?
>   puts "Extra files:"
>   extra.each { |f| puts f }
>   puts
> end
> 
> if !removed.empty?
>   puts "Removed files:"
>   removed.each { |f| puts f }
>   puts
> end
> 
> if extra.empty? && removed.empty?
>   puts "Identical."
> end
>