• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

SOLVED Command line to extract only specific folders and files from an archive

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

c627627

c(n*199780) Senior Member
Joined
Feb 18, 2002
EDIT: I of course know how to do this slowly/individually/manually.
This thread is about creating a single click .bat file to do it.


Greetings!
In order to create a Portable version of a program that gets updated frequently, I need to use either WinRAR or 7-Zip to extract only the following folders and files from an .exe Setup file. Can you help me make a .bat file that would accomplish that?

I need to extract only the following from a 32-Bit Setup file of this program: http://www.videohelp.com/software/PotPlayer

Folders:
Html
Logos
PxShader
Skins
Urllist

Files:
CmdLine.txt
PotPlayer.dll
PotPlayer.exe
PotPlayerMiniXP.exe


Saving this command with a .bat extension, extracts only the specified files/folders from C:\Setup32-Bit.exe to C:\1:

@ECHO OFF
"%PROGRAMFILES%\7-Zip\7z.exe" x C:\Setup32-Bit.exe -oc:\1 Html Logos PxShader Skins Urllist CmdLine.txt PotPlayer.dll PotPlayer.exe PotPlayerMiniXP.exe
 
Last edited:
Whether or not you can do this is going to depend on how the exe was packaged to begin with. If it's a WinRAR SFX or something similar, you'll probably just be able to do it with the unrar.exe command line utility included with WinRAR. If it's a custom installer, or even an installer packaged by another tool, you probably won't be able to do it.

It might be easier to run the exe silently in the background (if that's possible, again, it depends on the type of installer it is) to a temp location, copy your target files to overwrite existing, and then delete your temp install.
 
I need the code commands for the linked exe to make a .bat file. It can be done. Just need the codes.

The entire point of the thread is to make this a one click process instead of a manual selection process ;-)
 
Last edited:
You're currently able to open up the exe you linked above in WinRAR or 7zip, and extract only particular components of it? I downloaded it and attempted to do it with both the GUI and command line and wasn't able to.
 
Yes sir. I edited the first post to clarify the confusion about what this thread is about.
 
To clarify, I wasn't suggesting any sort of manual process, I was suggesting that it might be easier to programmatically do those things. I attempted to open the exe in WinRAR and wasn't able to do so.

Tried with 7zip and was able to get it working. CLI syntax will look something like this:
Code:
.\7z.exe x C:\path\to\your\exe.exe HTML Logos PxShader etc etc etc -oC:\path\to\where\you\want\it\to\go

Not sure if there's a limit to number of files/folders you can put in there, so so you could just do them in a foreach loop. Personally I'd use powershell instead of batch.
 
Hey, can you just post an actual code for one file and one folder to be extracted from C:\PotPlayerSetup-1.6.54915.exe to C:\1
 
This should do what you want. Change the variables accordingly, of course.
Code:
$zip = "C:\program files\7-zip\7z.exe"
$target = "c:\users\user\downloads\pp\pp.exe"
$destination = "C:\users\user\downloads\pp"
$filesToExtract = "HTML Logos PxShader Skins Urllist CmdLine.txt PotPlayer.dll PotPlayer.exe PotPlayerMiniXP.exe"
$files = $filesToExtract.Split(' ')
& $zip x -y $target $files "-o$($destination)"

Save it with extension .ps1 for a powershell file.
 
.ps1 opens with Notepad and furthermore special script permissions are needed for Power Shell etc. etc. :( complicated :(


boi, you made me spend 15 minutes finding this out the hard way. :D But I did it:

Saving this command with a .bat extension, extracts only the specified files/folders from C:\Setup32-Bit.exe to C:\1:

@ECHO OFF
"%PROGRAMFILES%\7-Zip\7z.exe" x C:\Setup32-Bit.exe -oc:\1 Html Logos PxShader Skins Urllist CmdLine.txt PotPlayer.dll PotPlayer.exe PotPlayerMiniXP.exe


=====

I need to extract only the following from a 32-Bit Setup file of this program: http://www.videohelp.com/software/PotPlayer

Folders:
Html
Logos
PxShader
Skins
Urllist

Files:
CmdLine.txt
PotPlayer.dll
PotPlayer.exe
PotPlayerMiniXP.exe[/QUOTE]
 
Last edited:
I have a deeply rooted hatred for all things batch, so I always encourage people to use Powershell. Batch is old and outdated, esoteric and clumsy at best. Out with the old, in the with new! Next you'll tell me you still use XP.... ;)

Glad you got it working.
 
Well, I'd like to address that.


Objective here is to create a portable version of a media player. There is no downloadable portable version but one can be created if only specific files/folders are extracted from the setup.exe file. I've been doing that manually each time a new version of the program was created, each time a new setup.exe file is released.

So the objective is to, with a single click!, create a portable version. Widest compatibility is key for things like this.

1. Notice the use of %PROGRAMFILES% in my batch file instead of C:\Program Files.
Neither my Windows 8 nor my Windows XP are installed on a drive called C: so the batch file works on all of my four operating systems. Whereas power shell file simply does not work when you double click on it.

2. I absolutely have to reboot into Windows XP for work, for you see, not even Windows 10 allows files and folders to be moved and grouped on different parts of the screen. This is *crucial* for some people's work, and I can think of at least one non work activity: making "mix tapes".

If I want to make a "mix tape" - I reboot into Windows XP, and group music files on different parts of the screen and figure out which ones go first, which second, and do it that way.

You cannot move files of folders on the screen in Windows 7/8/10 - you can actually only do this on the Desktop there but not inside any of the folders. There is a registry hack, but it breaks other things. It's beyond weird that you cannot turn auto-arrange OFF under Windows 7/8/10. The files and folders will ALWAYS be grouped alphabetically or by size or by whatever but you cannot turn auto-arrange off.


There are a couple of other reasons why I need to reboot into Windows XP. The search engine graphic user interface, which Windows 7/8/10 do not have. I have caught the "new" search engine missing hits and took screen shots. Windows XP file search engine is more reliable and it has a graphic user interface. It's irrelevant that Windows 7/8/10 engine is more powerful when it doesn't have a GUI - "nobody" knows what the search engine commands are under Windows 7/8/10...

If you wish to search by size or by date range or for a word inside a file - you are 100% screwed unless you are using a Windows XP file search engine or if you are in the 0.00001% of people who know Windows 7/8/10 search commands like for example
Date Range: 8/1/14..8/25/14
or
Size Range: 50MB..70MB
 
I was only giving you a hard time about XP, no need for explanations. :) FYI, you can also use environment variables inside powershell instead of hardcoding the path like in my example. Also, you can right click "Run with powershell." It's not quite as easy as just double clicking, but takes a couple milliseconds longer to do it that way. I understand that batch has its places (Windows XP environments being one of them), I'm just here to preach the good word of Powershell. :)
 
Back