r - Extract certain files from .zip -


is there way selectively extract .zip archive files names matching pattern?

for example, if want use .csv files archive , ignore other files.

current approach:

zipped_file_names <- unzip('some_archive.zip') # extracts everything, captures file names csv_nms <-  grep('csv', zipped_file_names, ignore.case=true, value=true) library('data.table') comb_tbl <- rbindlist(lapply(csv_nms,  function(x) cbind(fread(x, sep=',', header=true,                                                                 stringsasfactors=false),                                                           file_nm=x) ), fill=true )  

instead of selecting ones read (csv_nms), i'm looking way choose ones extract in first place.

i'm on v3.2.2 (windows).

thanks comment @user20650.

use 2 calls unzip. first list=true $name files. second files= extract files names match 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 )  

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -