Skip to content

Instantly share code, notes, and snippets.

@mark-cooper
Created March 5, 2012 04:35
Show Gist options
  • Select an option

  • Save mark-cooper/1976640 to your computer and use it in GitHub Desktop.

Select an option

Save mark-cooper/1976640 to your computer and use it in GitHub Desktop.
Reading and searching marc files in zip
require 'zip/zip'
require 'marc'
search = 'tower heist'
path = 'X:/Digital Projects/FTP files/files*/*'
Dir[path].each do |f|
if f =~ /\.zip$/
Zip::ZipFile.open(f) do |zipfile|
zipfile.each do |entry|
next if ! entry.file?
s = MARC::ForgivingReader.new(StringIO.new(entry.get_input_stream.read))
s.each { |r| puts f + ' : ' + entry.name + ' : ' + r['245'].value if r =~ /#{search}/i }
end
end
end
end
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment