Skip to content

Instantly share code, notes, and snippets.

@devyn
Created November 11, 2008 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devyn/24034 to your computer and use it in GitHub Desktop.
Save devyn/24034 to your computer and use it in GitHub Desktop.
a quick file indexer for ruby
# a quick file indexer for ruby
def checksum(file_loc)
sum = 0
File.open(file_loc){|f|f.each_byte{|b|sum^=b}}
sum
end
$index = []
def enter dir
(Dir.entries(dir) - %w(. ..)).each do |ent|
if File.directory? File.join(File.expand_path(dir), ent)
enter File.join(File.expand_path(dir), ent)
next
end
$index << {
'name' => File.join(File.expand_path(dir), ent),
'checksum' => checksum(File.join(File.expand_path(dir), ent))
}
end
end
enter ARGV.shift
require 'yaml'
print YAML.dump($index)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment