0

Is it possible to use a zsh script to unrar all directories within another directory?

As follows:

dir
|_dir1.rar
|_dir2.rar
|_dir3.rar

I would like the command not to include the cd. I will cd into the folder before executing the zsh script. The script should extract all .rar directories into the same folder with the same original directory name. For example dir1.rar should extract to dir1 and so on.

Hope this can be done.

1 Answers1

-1

Did you try the unrar itself?

unrar x archive.rar

If the archive has directories and subdirectories - they would be recreated.

White Owl
  • 4,511
  • 1
  • 4
  • 15
  • yes the problem is some .rar directories have hundreds of subdirectories that extract into the folder instead of into one. I have had to then manually move all of those subdirectories into a new folder. I would like it to know to move it all into a directory automatically so I can avoid this work. Does that make sense? – linuxuser24569 Mar 24 '23 at 01:09
  • Please note, unrar has two commands: `e` and `x`. Which one do you use? – White Owl Mar 24 '23 at 01:11
  • neither do what i am trying. option x still extracts all of the directories within the .rar into the folder (this could be thousands of directories) that i am cd in, and e extracts all of the files and everything into the directory i am cd in. i need them to extract to a new folder that is created with the name of the .rar and then extract into that folder - not the folder i am cd in. when it does that i have thousands of files i have to manually move into another folder. problem is some extract into their own folder and some dont so it creates a mess. – linuxuser24569 Mar 24 '23 at 01:27
  • `cd target; unrar x ../archive.rar` or `unrar x archive.rar target/` ? – White Owl Mar 24 '23 at 11:13