Is there a way to selectively extract from a .zip
archive those files with names matching a pattern?
For example, if I want to use all .csv
Thanks to comment from @user20650.
Use two calls to unzip
. First with list=TRUE
just to get the $Name
for the files. Second with files=
to extract only the files whose names match the pattern.
zipped_csv_names <- grep('\\.csv$', unzip('some_archive.zip', list=TRUE)$Name,
ignore.case=TRUE, value=TRUE)
unzip('some_archive.zip', files=zipped_csv_names)
comb_tbl <- rbindlist(lapply(zipped_csv_names,
function(x) cbind(fread(x, sep=',', header=TRUE,
stringsAsFactors=FALSE),
file_nm=x)), fill=TRUE )