I'm trying to extract filenames from rar packages in a directory. I'm using 7z which returns a multi-line string, and would like to search the output for "mkv", "avi", or "srt" files.
Here's my code:
ROOT_DIR = "/users/ken/extract"
# Check each directory for Rar packages
# Returns an arary of directories with filenames from the rar's
def checkdirs()
pkgdirs = {}
Dir.foreach(ROOT_DIR) do |d|
if !Dir.glob("#{ROOT_DIR}/#{d}/*.rar").empty?
rarlist = `7z l #{ROOT_DIR}/#{d}/*.rar`
puts rarlist # Returns multilinen output from 7z l
puts rarlist.scan('*.mkv').first
pkgdirs[d] = 'filename'
end
end
pkgdirs
end
I can get the 7z output but I can't figure out how to search the output for my strings. How can I search the output and return the matching lines?
This is an example of the 7z output:
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=utf8,Utf16=on,HugeFiles=on,64 bits,8 CPUs x64)
Scanning the drive for archives:
1 file, 15000000 bytes (15 MiB)
Listing archive: Gotham.S03E19.HDTV.x264-KILLERS/gotham.s03e19.hdtv.x264-killers.rar
--
Path = Gotham.S03E19.HDTV.x264-KILLERS/gotham.s03e19.hdtv.x264-killers.rar
Type = Rar
Physical Size = 15000000
Total Physical Size = 285988640
Characteristics = Volume FirstVolume VolCRC
Solid = -
Blocks = 1
Multivolume = +
Volume Index = 0
Volumes = 20
Date Time Attr Size Compressed Name
------------------- ----- ------------ ------------ ------------------------
2017-05-23 02:30:52 ..... 285986500 285986500 Gotham.S03E19.HDTV.x264-KILLERS.mkv
------------------- ----- ------------ ------------ ------------------------
2017-05-23 02:30:52 285986500 285986500 1 files
------------------- ----- ------------ ------------ ------------------------
2017-05-23 02:30:52 285986500 285986500 1 files
Archives: 1
Volumes: 20
Total archives size: 285988640
I expect this output:
2017-05-23 02:30:52 ..... 285986500 285986500 Gotham.S03E19.HDTV.x264-KILLERS.mkv