Sample Header Ad - 728x90

Unrar to folder with same name as archive

7 votes
3 answers
6188 views
I have a lot of rar files - Folder/ --- Spain.rar --- Germany.rar --- Italy.rar All the files contains no root folder so it's just files. What I want to achieve when extracting is this structure: - Folder/ -- Spain/ ---- Spain_file1.txt ---- Spain_file2.txt -- Germany/ ---- Germany_file1.txt ---- Germany_file2.txt -- Italy/ ---- Italy_file1.txt ---- Italy_file2.txt So that a folder with the name of the archive is created and the archive is extracted to it. I found this bash example in another thread but it's not working for me, it's trying to create one folder with all the files as name. #!/bin/bash for archive in "$(find . -name '*.rar')"; do destination="${archive%.rar}" if [ ! -d "$destination" ] ; then mkdir "$destination"; fi unrar e "$archive" "$destination" done Any ideas how I can do this?
Asked by Dennis Wiencken (81 rep)
Oct 19, 2018, 10:52 AM
Last activity: Dec 12, 2021, 10:08 PM