Created
March 5, 2012 04:35
-
-
Save mark-cooper/1976640 to your computer and use it in GitHub Desktop.
Reading and searching marc files in zip
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
| 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