0

I trying to do a data frame/list/vector with a list of folders inside a zip and rar file.

I have a folder with a lot of zip and rar files; Each zip and rar file has one folder and inside this folder has a lot of folders and files; I would get the names of these folders inside a zipped folder;

I try:

unzip(zipfile = "teste1.zip", list = TRUE)

and it show me:

                            Name Length                Date
1                        teste1/      0 2022-08-03 15:49:00
2            teste1/Nova pasta1/      0 2022-08-03 15:50:00
3 teste1/Nova pasta1/texto11.txt      0 2022-08-03 15:49:00
4              teste1/texto1.txt      0 2022-08-03 15:49:00

But I would like to get just the names of second directory (Nova pasta 1)

Thanks a lot

Wimpel
  • 26,031
  • 1
  • 20
  • 37
Wilson Souza
  • 830
  • 4
  • 12
  • For zip files, use the builtin `unzip` function, with argument `list = T`. Not sure there is the equivalent for RAR files. There is still the possibility to parse the output of `unrar -l`. –  Aug 03 '22 at 19:39

2 Answers2

0

for ZIP:

unzip -l archive.zip

for RAR:

unrar -l archive.rar
Telinov Dmitri
  • 411
  • 4
  • 12
0

You can unzip zip files in R using the base R function unzip. I am not sure if there is a similar solution for RAR files. Once unzipped, you can use the base R function list.files() to list the names of the files and folders in any directory on your computer, e.g. list.files(path="mypath").

  • No need to actually unzip the file to get the listing from the `unzip` function. Look up the option `list = T` in the documentation. –  Aug 04 '22 at 01:32