7zip / winrar command to extract a folder with path intact to specific folder but excluding parent source path

StackOverflow https://stackoverflow.com/questions/23171279

  •  06-07-2023
  •  | 
  •  

Question

example

There is a file "sample.rar".

Folder structure is: "rising\dawn\ and here there are many (folders1, folders2 and file1, file2)" in this archive.

i have used following command

7z.exe x "sample.rar" "rising\dawn\*" -oi:\delete

The result is: all files and folders in "rising\dawn\" are extracted to "i:\delete" folder but the empty parent folders "rising\dawn\" are also created in destination folder.

e.g. destination looks:

i:\delete\rising\dawn\folder1\file1.bmp

i:\delete\rising\dawn\folder2\subfolder

i:\delete\rising\dawn\file1.txt

i:\delete\rising\dawn\file2.txt

i don't want "rising\dawn\" empty folders to be created but the folder structure there onwards must be as is in the archive.

i want the result:

i:\delete\folder1\file1.bmp

i:\delete\folder2\subfolder

i:\delete\file1.txt

i:\delete\file2.txt

at last i found a way out solution. thanks to the winrar support. i have accepted it as an answer below.

if you find the question useful don't forget to click the up-vote button.

Was it helpful?

Solution

Finally this gave me the result.

Thanks to winrar support.

rar x -ep1 sample.rar rising\dawn\* d:\e\delete\

i have tried other answers given here, this is the only correct answer.
don't forget to upvote.

OTHER TIPS

You can extract the archive normally and

1) move the lower level folder/files to where you would like it, then
2) remove the extra top level archive folders.

Code to do so will depend on the exact task.

Using e command instead of x and add -r option works well.

Like this:

7z.exe e -r "sample.rar" "rising\dawn\*" -oi:\delete

My executable version is "7-Zip [64] 9.20 2010-11-18", And the platform is Windows 8.1.

This command line eliminates unnecessary parent folders and preserves the hierarchy of folders.

You need to use the e command rather than the x command:

7z.exe e "sample.rar" "scholar\update\*" -oi:\delete

Using e instead of x means 7zip will extract all matching files into the same folder (as specified via the -so switch, or the current directory if this isn't specified) rather than preserving the folder structure from inside the archive.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top