How can I unzip a .tar.gz in one step (using 7-Zip)?
I am using 7-Zip on Windows XP and whenever I download a .tar.gz file it takes me two steps to completely extract the file(s).
- I right-click on the example.tar.gz file and choose 7-Zip --> Extract Here from the context menu.
- I then take the resulting example.tar file and the right-click again and choose 7-Zip --> Extract Here from the context menu.
Is there a way through the context menu to do this in one step?
windows-xp 7-zip
add a comment |
I am using 7-Zip on Windows XP and whenever I download a .tar.gz file it takes me two steps to completely extract the file(s).
- I right-click on the example.tar.gz file and choose 7-Zip --> Extract Here from the context menu.
- I then take the resulting example.tar file and the right-click again and choose 7-Zip --> Extract Here from the context menu.
Is there a way through the context menu to do this in one step?
windows-xp 7-zip
add a comment |
I am using 7-Zip on Windows XP and whenever I download a .tar.gz file it takes me two steps to completely extract the file(s).
- I right-click on the example.tar.gz file and choose 7-Zip --> Extract Here from the context menu.
- I then take the resulting example.tar file and the right-click again and choose 7-Zip --> Extract Here from the context menu.
Is there a way through the context menu to do this in one step?
windows-xp 7-zip
I am using 7-Zip on Windows XP and whenever I download a .tar.gz file it takes me two steps to completely extract the file(s).
- I right-click on the example.tar.gz file and choose 7-Zip --> Extract Here from the context menu.
- I then take the resulting example.tar file and the right-click again and choose 7-Zip --> Extract Here from the context menu.
Is there a way through the context menu to do this in one step?
windows-xp 7-zip
windows-xp 7-zip
edited Dec 7 '09 at 20:31
Breakthrough
31.6k992140
31.6k992140
asked Dec 7 '09 at 20:01
quickcelquickcel
3,56811723
3,56811723
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
Not really. A .tar.gz or .tgz file really is two formats: .tar
is the archive, and .gz
is the compression. So the first step decompresses, and the second step extracts the archive.
To do it all in one step, you need the tar
program. Cygwin includes this.
tar xzvf foobaz.tar.gz
; x = eXtract
; z = filter through gZip
; v = be Verbose (show activity)
; f = filename
You could also do it "in one step" by opening the file in the 7-zip GUI: Open the .tar.gz
file, double click the included .tar
file, then extract those files to your location of choice.
There's a long running thread here of people asking/voting for one-step handling of tgz and bz2 files. The lack action thus far indicates it's not going to happen until someone steps and contributes meaningfully (code, money, something).
68
If 7zip were smart, it would do it in one step by default, since 99.99% of the time that's what the user wants to do. In fact, this is WinRar's default operation.
– davr
Dec 7 '09 at 20:35
4
@davr: 7-zip is an open source effort; feel free to request this feature. this is how v4.65 operates; i haven't tried the newer v9.x alphas, so it may already be included.
– quack quixote
Dec 7 '09 at 20:52
Yah, this is what I miss from WinRar's operation. I could confirm that up to today, Oct2012, 7zip still doesn't auto decompress with 1 step. sigh
– fedmich
Oct 19 '12 at 13:18
6
Note that the "in one step" instructions doesn't actually do it in one step, it actually decompresses the .gz into a temporary folder, then opens the .tar file in 7-zip. When the archives are small enough, it's hardly noticeable, but it's very noticeable on large archives. Just thought that deserved clarification.
– naasking
Oct 25 '13 at 18:29
There is a new answer with the one-step instructions.
– Barett
Jun 1 '18 at 2:40
|
show 1 more comment
Old question, but I was struggling with it today so here's my 2c. The 7zip commandline tool "7z.exe" (I have v9.22 installed) can write to stdout and read from stdin so you can do without the intermediate tar file by using a pipe:
7z x "somename.tar.gz" -so | 7z x -aoa -si -ttar -o"somename"
Where:
x = Extract with full paths command
-so = write to stdout switch
-si = read from stdin switch
-aoa = Overwrite all existing files without prompt.
-ttar = Treat the stdin byte stream as a TAR file
-o = output directory
See the help file (7-zip.chm) in the install directory for more info on the command line commands and switches.
You can create a context menu entry for .tar.gz/.tgz files that calls the above command using regedit or a 3rd party tool like stexbar.
what does the -aoa switch do? It's not listed in -? page
– Superole
Oct 23 '13 at 8:40
2
..ahh but it is in the help file; -ao[a|s|t|u] (overwrite mode). thus: -aoa = overwrite all existing files w/o prompt
– Superole
Oct 23 '13 at 8:47
Good answer but the loop was not asked for by OP. Joachim's (similar) one-line answer is great and to the point!
– Jason
Jun 7 '18 at 23:31
@Jason that answer is exactly the same as my SO answer stackoverflow.com/a/14699663/737471 I may just edit this one...
– user2856
Jun 7 '18 at 23:35
add a comment |
Starting with 7-zip 9.04 there is a command-line option to do the combined extraction without using intermediate storage for the plain .tar
file:
7z x -tgzip -so theinputfile.tgz | 7z x -si -ttar
-tgzip
is needed if the input file is named .tgz
instead of .tar.gz
.
Any way to get that into the Windows 10 Explorer context menu?
– Brian Leishman
Aug 29 '18 at 19:57
add a comment |
You're using Windows XP, so you should have Windows Scripting Host installed by default. With that being said, here's a WSH JScript script to do what you need. Just copy the code to a file name xtract.bat or something along those lines (Can be whatever as long as it has the extension .bat
), and run:
xtract.bat example.tar.gz
By default, the script will check the folder of the script, as well as your system's PATH
environment variable for 7z.exe. If you want to change how it looks for stuff, you can change the SevenZipExe variable at the top of the script to whatever you want the executable name to be. (For instance, 7za.exe or 7z-real.exe) You can also set a default directory for the executable by changing SevenZipDir. So if 7z.exe
is at C:Windowssystem327z.exe
, you'd put:
var SevenZipDir = "C:\Windows\system32";
Anyways, here's the script:
@set @junk=1 /* vim:set ft=javascript:
@echo off
cscript //nologo //e:jscript "%~dpn0.bat" %*
goto :eof
*/
/* Settings */
var SevenZipDir = undefined;
var SevenZipExe = "7z.exe";
var ArchiveExts = ["zip", "tar", "gz", "bzip", "bz", "tgz", "z", "7z", "bz2", "rar"]
/* Multi-use instances */
var WSH = new ActiveXObject("WScript.Shell");
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var __file__ = WScript.ScriptFullName;
var __dir__ = FSO.GetParentFolderName(__file__);
var PWD = WSH.CurrentDirectory;
/* Prototypes */
(function(obj) {
obj.has = function object_has(key) {
return defined(this[key]);
};
return obj;
})(this.Object.prototype);
(function(str) {
str.trim = function str_trim() {
return this.replace(/^ss*/, '').replace(/ss*$/, '');
};
})(this.String.prototype);
(function(arr) {
arr.contains = function arr_contains(needle) {
for (var i in this) {
if (this[i] == needle) {
return true;
}
}
return false;
}
})(this.Array.prototype);
/* Utility functions */
function defined(obj)
{
return typeof(obj) != "undefined";
}
function emptyStr(obj)
{
return !(defined(obj) && String(obj).length);
}
/* WSH-specific Utility Functions */
function echo()
{
if(!arguments.length) return;
var msg = "";
for (var n = 0; n < arguments.length; n++) {
msg += arguments[n];
msg += " ";
}
if(!emptyStr(msg))
WScript.Echo(msg);
}
function fatal(msg)
{
echo("Fatal Error:", msg);
WScript.Quit(1);
}
function findExecutable()
{
// This function searches the directories in;
// the PATH array for the specified file name;
var dirTest = emptyStr(SevenZipDir) ? __dir__ : SevenZipDir;
var exec = SevenZipExe;
var strTestPath = FSO.BuildPath(dirTest, exec);
if (FSO.FileExists(strTestPath))
return FSO.GetAbsolutePathName(strTestPath);
var arrPath = String(
dirTest + ";" +
WSH.ExpandEnvironmentStrings("%PATH%")
).split(";");
for(var i in arrPath) {
// Skip empty directory values, caused by the PATH;
// variable being terminated with a semicolon;
if (arrPath[i] == "")
continue;
// Build a fully qualified path of the file to test for;
strTestPath = FSO.BuildPath(arrPath[i], exec);
// Check if (that file exists;
if (FSO.FileExists(strTestPath))
return FSO.GetAbsolutePathName(strTestPath);
}
return "";
}
function readall(oExec)
{
if (!oExec.StdOut.AtEndOfStream)
return oExec.StdOut.ReadAll();
if (!oExec.StdErr.AtEndOfStream)
return oExec.StdErr.ReadAll();
return -1;
}
function xtract(exec, archive)
{
var splitExt = /^(.+).(w+)$/;
var strTmp = FSO.GetFileName(archive);
WSH.CurrentDirectory = FSO.GetParentFolderName(archive);
while(true) {
var pathParts = splitExt.exec(strTmp);
if(!pathParts) {
echo("No extension detected for", strTmp + ".", "Skipping..");
break;
}
var ext = pathParts[2].toLowerCase();
if(!ArchiveExts.contains(ext)) {
echo("Extension", ext, "not recognized. Skipping.");
break;
}
echo("Extracting", strTmp + "..");
var oExec = WSH.Exec('"' + exec + '" x -bd "' + strTmp + '"');
var allInput = "";
var tryCount = 0;
while (true)
{
var input = readall(oExec);
if (-1 == input) {
if (tryCount++ > 10 && oExec.Status == 1)
break;
WScript.Sleep(100);
} else {
allInput += input;
tryCount = 0;
}
}
if(oExec. ExitCode!= 0) {
echo("Non-zero return code detected.");
break;
}
WScript.Echo(allInput);
strTmp = pathParts[1];
if(!FSO.FileExists(strTmp))
break;
}
WSH.CurrentDirectory = PWD;
}
function printUsage()
{
echo("Usage:rn", __file__, "archive1 [archive2] ...");
WScript.Quit(0);
}
function main(args)
{
var exe = findExecutable();
if(emptyStr(exe))
fatal("Could not find 7zip executable.");
if(!args.length || args(0) == "-h" || args(0) == "--help" || args(0) == "/?")
printUsage();
for (var i = 0; i < args.length; i++) {
var archive = FSO.GetAbsolutePathName(args(i));
if(!FSO.FileExists(archive)) {
echo("File", archive, "does not exist. Skipping..");
continue;
}
xtract(exe, archive);
}
echo("rnDone.");
}
main(WScript.Arguments.Unnamed);
Not that I'm aware of. I initially found it in the following source repository: github.com/ynkdir/winscript It works, because the WSH jscript engine apparently ignores the first bit, up until the comment begins. More information can be found at: stackoverflow.com/questions/4999395/…
– Charles Grunwald
Jun 11 '13 at 1:39
found this: javascriptkit.com/javatutors/conditionalcompile2.shtml which seems to indicate that@set @var = value
is JScript syntax for declaring compile-time variables. So it's both valid JScript and a CMD command
– hdgarrood
Jun 11 '13 at 10:36
add a comment |
As you can see 7-Zip is not very good at this. People have been asking for
tarball atomic operation since 2009. Here is a small program
(490 KB) in Go that can do it, I compiled it for you.
package main
import (
"archive/tar"
"compress/gzip"
"flag"
"fmt"
"io"
"os"
"strings"
)
func main() {
flag.Parse() // get the arguments from command line
sourcefile := flag.Arg(0)
if sourcefile == "" {
fmt.Println("Usage : go-untar sourcefile.tar.gz")
os.Exit(1)
}
file, err := os.Open(sourcefile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer file.Close()
var fileReader io.ReadCloser = file
// just in case we are reading a tar.gz file,
// add a filter to handle gzipped file
if strings.HasSuffix(sourcefile, ".gz") {
if fileReader, err = gzip.NewReader(file); err != nil {
fmt.Println(err)
os.Exit(1)
}
defer fileReader.Close()
}
tarBallReader := tar.NewReader(fileReader)
// Extracting tarred files
for {
header, err := tarBallReader.Next()
if err != nil {
if err == io.EOF {
break
}
fmt.Println(err)
os.Exit(1)
}
// get the individual filename and extract to the current directory
filename := header.Name
switch header.Typeflag {
case tar.TypeDir:
// handle directory
fmt.Println("Creating directory :", filename)
// or use 0755 if you prefer
err = os.MkdirAll(filename, os.FileMode(header.Mode))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case tar.TypeReg:
// handle normal file
fmt.Println("Untarring :", filename)
writer, err := os.Create(filename)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
io.Copy(writer, tarBallReader)
err = os.Chmod(filename, os.FileMode(header.Mode))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
writer.Close()
default:
fmt.Printf("Unable to untar type : %c in file %s", header.Typeflag,
filename)
}
}
}
add a comment |
7za is work properly as below:
7za.exe x D:pkg-tempProd-Rtx-Service.tgz -so | 7za.exe x -si -ttar -oD:pkg-tempProd-Rtx-Service
3
Can you add some context around how this command works? Please see How to Answer and take our tour.
– Burgi
Aug 31 '18 at 9:08
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f80019%2fhow-can-i-unzip-a-tar-gz-in-one-step-using-7-zip%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
Not really. A .tar.gz or .tgz file really is two formats: .tar
is the archive, and .gz
is the compression. So the first step decompresses, and the second step extracts the archive.
To do it all in one step, you need the tar
program. Cygwin includes this.
tar xzvf foobaz.tar.gz
; x = eXtract
; z = filter through gZip
; v = be Verbose (show activity)
; f = filename
You could also do it "in one step" by opening the file in the 7-zip GUI: Open the .tar.gz
file, double click the included .tar
file, then extract those files to your location of choice.
There's a long running thread here of people asking/voting for one-step handling of tgz and bz2 files. The lack action thus far indicates it's not going to happen until someone steps and contributes meaningfully (code, money, something).
68
If 7zip were smart, it would do it in one step by default, since 99.99% of the time that's what the user wants to do. In fact, this is WinRar's default operation.
– davr
Dec 7 '09 at 20:35
4
@davr: 7-zip is an open source effort; feel free to request this feature. this is how v4.65 operates; i haven't tried the newer v9.x alphas, so it may already be included.
– quack quixote
Dec 7 '09 at 20:52
Yah, this is what I miss from WinRar's operation. I could confirm that up to today, Oct2012, 7zip still doesn't auto decompress with 1 step. sigh
– fedmich
Oct 19 '12 at 13:18
6
Note that the "in one step" instructions doesn't actually do it in one step, it actually decompresses the .gz into a temporary folder, then opens the .tar file in 7-zip. When the archives are small enough, it's hardly noticeable, but it's very noticeable on large archives. Just thought that deserved clarification.
– naasking
Oct 25 '13 at 18:29
There is a new answer with the one-step instructions.
– Barett
Jun 1 '18 at 2:40
|
show 1 more comment
Not really. A .tar.gz or .tgz file really is two formats: .tar
is the archive, and .gz
is the compression. So the first step decompresses, and the second step extracts the archive.
To do it all in one step, you need the tar
program. Cygwin includes this.
tar xzvf foobaz.tar.gz
; x = eXtract
; z = filter through gZip
; v = be Verbose (show activity)
; f = filename
You could also do it "in one step" by opening the file in the 7-zip GUI: Open the .tar.gz
file, double click the included .tar
file, then extract those files to your location of choice.
There's a long running thread here of people asking/voting for one-step handling of tgz and bz2 files. The lack action thus far indicates it's not going to happen until someone steps and contributes meaningfully (code, money, something).
68
If 7zip were smart, it would do it in one step by default, since 99.99% of the time that's what the user wants to do. In fact, this is WinRar's default operation.
– davr
Dec 7 '09 at 20:35
4
@davr: 7-zip is an open source effort; feel free to request this feature. this is how v4.65 operates; i haven't tried the newer v9.x alphas, so it may already be included.
– quack quixote
Dec 7 '09 at 20:52
Yah, this is what I miss from WinRar's operation. I could confirm that up to today, Oct2012, 7zip still doesn't auto decompress with 1 step. sigh
– fedmich
Oct 19 '12 at 13:18
6
Note that the "in one step" instructions doesn't actually do it in one step, it actually decompresses the .gz into a temporary folder, then opens the .tar file in 7-zip. When the archives are small enough, it's hardly noticeable, but it's very noticeable on large archives. Just thought that deserved clarification.
– naasking
Oct 25 '13 at 18:29
There is a new answer with the one-step instructions.
– Barett
Jun 1 '18 at 2:40
|
show 1 more comment
Not really. A .tar.gz or .tgz file really is two formats: .tar
is the archive, and .gz
is the compression. So the first step decompresses, and the second step extracts the archive.
To do it all in one step, you need the tar
program. Cygwin includes this.
tar xzvf foobaz.tar.gz
; x = eXtract
; z = filter through gZip
; v = be Verbose (show activity)
; f = filename
You could also do it "in one step" by opening the file in the 7-zip GUI: Open the .tar.gz
file, double click the included .tar
file, then extract those files to your location of choice.
There's a long running thread here of people asking/voting for one-step handling of tgz and bz2 files. The lack action thus far indicates it's not going to happen until someone steps and contributes meaningfully (code, money, something).
Not really. A .tar.gz or .tgz file really is two formats: .tar
is the archive, and .gz
is the compression. So the first step decompresses, and the second step extracts the archive.
To do it all in one step, you need the tar
program. Cygwin includes this.
tar xzvf foobaz.tar.gz
; x = eXtract
; z = filter through gZip
; v = be Verbose (show activity)
; f = filename
You could also do it "in one step" by opening the file in the 7-zip GUI: Open the .tar.gz
file, double click the included .tar
file, then extract those files to your location of choice.
There's a long running thread here of people asking/voting for one-step handling of tgz and bz2 files. The lack action thus far indicates it's not going to happen until someone steps and contributes meaningfully (code, money, something).
edited Dec 2 '16 at 1:35
Steven Penny
1
1
answered Dec 7 '09 at 20:07
quack quixotequack quixote
35.3k1087119
35.3k1087119
68
If 7zip were smart, it would do it in one step by default, since 99.99% of the time that's what the user wants to do. In fact, this is WinRar's default operation.
– davr
Dec 7 '09 at 20:35
4
@davr: 7-zip is an open source effort; feel free to request this feature. this is how v4.65 operates; i haven't tried the newer v9.x alphas, so it may already be included.
– quack quixote
Dec 7 '09 at 20:52
Yah, this is what I miss from WinRar's operation. I could confirm that up to today, Oct2012, 7zip still doesn't auto decompress with 1 step. sigh
– fedmich
Oct 19 '12 at 13:18
6
Note that the "in one step" instructions doesn't actually do it in one step, it actually decompresses the .gz into a temporary folder, then opens the .tar file in 7-zip. When the archives are small enough, it's hardly noticeable, but it's very noticeable on large archives. Just thought that deserved clarification.
– naasking
Oct 25 '13 at 18:29
There is a new answer with the one-step instructions.
– Barett
Jun 1 '18 at 2:40
|
show 1 more comment
68
If 7zip were smart, it would do it in one step by default, since 99.99% of the time that's what the user wants to do. In fact, this is WinRar's default operation.
– davr
Dec 7 '09 at 20:35
4
@davr: 7-zip is an open source effort; feel free to request this feature. this is how v4.65 operates; i haven't tried the newer v9.x alphas, so it may already be included.
– quack quixote
Dec 7 '09 at 20:52
Yah, this is what I miss from WinRar's operation. I could confirm that up to today, Oct2012, 7zip still doesn't auto decompress with 1 step. sigh
– fedmich
Oct 19 '12 at 13:18
6
Note that the "in one step" instructions doesn't actually do it in one step, it actually decompresses the .gz into a temporary folder, then opens the .tar file in 7-zip. When the archives are small enough, it's hardly noticeable, but it's very noticeable on large archives. Just thought that deserved clarification.
– naasking
Oct 25 '13 at 18:29
There is a new answer with the one-step instructions.
– Barett
Jun 1 '18 at 2:40
68
68
If 7zip were smart, it would do it in one step by default, since 99.99% of the time that's what the user wants to do. In fact, this is WinRar's default operation.
– davr
Dec 7 '09 at 20:35
If 7zip were smart, it would do it in one step by default, since 99.99% of the time that's what the user wants to do. In fact, this is WinRar's default operation.
– davr
Dec 7 '09 at 20:35
4
4
@davr: 7-zip is an open source effort; feel free to request this feature. this is how v4.65 operates; i haven't tried the newer v9.x alphas, so it may already be included.
– quack quixote
Dec 7 '09 at 20:52
@davr: 7-zip is an open source effort; feel free to request this feature. this is how v4.65 operates; i haven't tried the newer v9.x alphas, so it may already be included.
– quack quixote
Dec 7 '09 at 20:52
Yah, this is what I miss from WinRar's operation. I could confirm that up to today, Oct2012, 7zip still doesn't auto decompress with 1 step. sigh
– fedmich
Oct 19 '12 at 13:18
Yah, this is what I miss from WinRar's operation. I could confirm that up to today, Oct2012, 7zip still doesn't auto decompress with 1 step. sigh
– fedmich
Oct 19 '12 at 13:18
6
6
Note that the "in one step" instructions doesn't actually do it in one step, it actually decompresses the .gz into a temporary folder, then opens the .tar file in 7-zip. When the archives are small enough, it's hardly noticeable, but it's very noticeable on large archives. Just thought that deserved clarification.
– naasking
Oct 25 '13 at 18:29
Note that the "in one step" instructions doesn't actually do it in one step, it actually decompresses the .gz into a temporary folder, then opens the .tar file in 7-zip. When the archives are small enough, it's hardly noticeable, but it's very noticeable on large archives. Just thought that deserved clarification.
– naasking
Oct 25 '13 at 18:29
There is a new answer with the one-step instructions.
– Barett
Jun 1 '18 at 2:40
There is a new answer with the one-step instructions.
– Barett
Jun 1 '18 at 2:40
|
show 1 more comment
Old question, but I was struggling with it today so here's my 2c. The 7zip commandline tool "7z.exe" (I have v9.22 installed) can write to stdout and read from stdin so you can do without the intermediate tar file by using a pipe:
7z x "somename.tar.gz" -so | 7z x -aoa -si -ttar -o"somename"
Where:
x = Extract with full paths command
-so = write to stdout switch
-si = read from stdin switch
-aoa = Overwrite all existing files without prompt.
-ttar = Treat the stdin byte stream as a TAR file
-o = output directory
See the help file (7-zip.chm) in the install directory for more info on the command line commands and switches.
You can create a context menu entry for .tar.gz/.tgz files that calls the above command using regedit or a 3rd party tool like stexbar.
what does the -aoa switch do? It's not listed in -? page
– Superole
Oct 23 '13 at 8:40
2
..ahh but it is in the help file; -ao[a|s|t|u] (overwrite mode). thus: -aoa = overwrite all existing files w/o prompt
– Superole
Oct 23 '13 at 8:47
Good answer but the loop was not asked for by OP. Joachim's (similar) one-line answer is great and to the point!
– Jason
Jun 7 '18 at 23:31
@Jason that answer is exactly the same as my SO answer stackoverflow.com/a/14699663/737471 I may just edit this one...
– user2856
Jun 7 '18 at 23:35
add a comment |
Old question, but I was struggling with it today so here's my 2c. The 7zip commandline tool "7z.exe" (I have v9.22 installed) can write to stdout and read from stdin so you can do without the intermediate tar file by using a pipe:
7z x "somename.tar.gz" -so | 7z x -aoa -si -ttar -o"somename"
Where:
x = Extract with full paths command
-so = write to stdout switch
-si = read from stdin switch
-aoa = Overwrite all existing files without prompt.
-ttar = Treat the stdin byte stream as a TAR file
-o = output directory
See the help file (7-zip.chm) in the install directory for more info on the command line commands and switches.
You can create a context menu entry for .tar.gz/.tgz files that calls the above command using regedit or a 3rd party tool like stexbar.
what does the -aoa switch do? It's not listed in -? page
– Superole
Oct 23 '13 at 8:40
2
..ahh but it is in the help file; -ao[a|s|t|u] (overwrite mode). thus: -aoa = overwrite all existing files w/o prompt
– Superole
Oct 23 '13 at 8:47
Good answer but the loop was not asked for by OP. Joachim's (similar) one-line answer is great and to the point!
– Jason
Jun 7 '18 at 23:31
@Jason that answer is exactly the same as my SO answer stackoverflow.com/a/14699663/737471 I may just edit this one...
– user2856
Jun 7 '18 at 23:35
add a comment |
Old question, but I was struggling with it today so here's my 2c. The 7zip commandline tool "7z.exe" (I have v9.22 installed) can write to stdout and read from stdin so you can do without the intermediate tar file by using a pipe:
7z x "somename.tar.gz" -so | 7z x -aoa -si -ttar -o"somename"
Where:
x = Extract with full paths command
-so = write to stdout switch
-si = read from stdin switch
-aoa = Overwrite all existing files without prompt.
-ttar = Treat the stdin byte stream as a TAR file
-o = output directory
See the help file (7-zip.chm) in the install directory for more info on the command line commands and switches.
You can create a context menu entry for .tar.gz/.tgz files that calls the above command using regedit or a 3rd party tool like stexbar.
Old question, but I was struggling with it today so here's my 2c. The 7zip commandline tool "7z.exe" (I have v9.22 installed) can write to stdout and read from stdin so you can do without the intermediate tar file by using a pipe:
7z x "somename.tar.gz" -so | 7z x -aoa -si -ttar -o"somename"
Where:
x = Extract with full paths command
-so = write to stdout switch
-si = read from stdin switch
-aoa = Overwrite all existing files without prompt.
-ttar = Treat the stdin byte stream as a TAR file
-o = output directory
See the help file (7-zip.chm) in the install directory for more info on the command line commands and switches.
You can create a context menu entry for .tar.gz/.tgz files that calls the above command using regedit or a 3rd party tool like stexbar.
edited Jun 7 '18 at 23:37
answered Feb 5 '13 at 2:07
user2856user2856
34425
34425
what does the -aoa switch do? It's not listed in -? page
– Superole
Oct 23 '13 at 8:40
2
..ahh but it is in the help file; -ao[a|s|t|u] (overwrite mode). thus: -aoa = overwrite all existing files w/o prompt
– Superole
Oct 23 '13 at 8:47
Good answer but the loop was not asked for by OP. Joachim's (similar) one-line answer is great and to the point!
– Jason
Jun 7 '18 at 23:31
@Jason that answer is exactly the same as my SO answer stackoverflow.com/a/14699663/737471 I may just edit this one...
– user2856
Jun 7 '18 at 23:35
add a comment |
what does the -aoa switch do? It's not listed in -? page
– Superole
Oct 23 '13 at 8:40
2
..ahh but it is in the help file; -ao[a|s|t|u] (overwrite mode). thus: -aoa = overwrite all existing files w/o prompt
– Superole
Oct 23 '13 at 8:47
Good answer but the loop was not asked for by OP. Joachim's (similar) one-line answer is great and to the point!
– Jason
Jun 7 '18 at 23:31
@Jason that answer is exactly the same as my SO answer stackoverflow.com/a/14699663/737471 I may just edit this one...
– user2856
Jun 7 '18 at 23:35
what does the -aoa switch do? It's not listed in -? page
– Superole
Oct 23 '13 at 8:40
what does the -aoa switch do? It's not listed in -? page
– Superole
Oct 23 '13 at 8:40
2
2
..ahh but it is in the help file; -ao[a|s|t|u] (overwrite mode). thus: -aoa = overwrite all existing files w/o prompt
– Superole
Oct 23 '13 at 8:47
..ahh but it is in the help file; -ao[a|s|t|u] (overwrite mode). thus: -aoa = overwrite all existing files w/o prompt
– Superole
Oct 23 '13 at 8:47
Good answer but the loop was not asked for by OP. Joachim's (similar) one-line answer is great and to the point!
– Jason
Jun 7 '18 at 23:31
Good answer but the loop was not asked for by OP. Joachim's (similar) one-line answer is great and to the point!
– Jason
Jun 7 '18 at 23:31
@Jason that answer is exactly the same as my SO answer stackoverflow.com/a/14699663/737471 I may just edit this one...
– user2856
Jun 7 '18 at 23:35
@Jason that answer is exactly the same as my SO answer stackoverflow.com/a/14699663/737471 I may just edit this one...
– user2856
Jun 7 '18 at 23:35
add a comment |
Starting with 7-zip 9.04 there is a command-line option to do the combined extraction without using intermediate storage for the plain .tar
file:
7z x -tgzip -so theinputfile.tgz | 7z x -si -ttar
-tgzip
is needed if the input file is named .tgz
instead of .tar.gz
.
Any way to get that into the Windows 10 Explorer context menu?
– Brian Leishman
Aug 29 '18 at 19:57
add a comment |
Starting with 7-zip 9.04 there is a command-line option to do the combined extraction without using intermediate storage for the plain .tar
file:
7z x -tgzip -so theinputfile.tgz | 7z x -si -ttar
-tgzip
is needed if the input file is named .tgz
instead of .tar.gz
.
Any way to get that into the Windows 10 Explorer context menu?
– Brian Leishman
Aug 29 '18 at 19:57
add a comment |
Starting with 7-zip 9.04 there is a command-line option to do the combined extraction without using intermediate storage for the plain .tar
file:
7z x -tgzip -so theinputfile.tgz | 7z x -si -ttar
-tgzip
is needed if the input file is named .tgz
instead of .tar.gz
.
Starting with 7-zip 9.04 there is a command-line option to do the combined extraction without using intermediate storage for the plain .tar
file:
7z x -tgzip -so theinputfile.tgz | 7z x -si -ttar
-tgzip
is needed if the input file is named .tgz
instead of .tar.gz
.
answered Jan 7 '18 at 20:23
Joachim SauerJoachim Sauer
895612
895612
Any way to get that into the Windows 10 Explorer context menu?
– Brian Leishman
Aug 29 '18 at 19:57
add a comment |
Any way to get that into the Windows 10 Explorer context menu?
– Brian Leishman
Aug 29 '18 at 19:57
Any way to get that into the Windows 10 Explorer context menu?
– Brian Leishman
Aug 29 '18 at 19:57
Any way to get that into the Windows 10 Explorer context menu?
– Brian Leishman
Aug 29 '18 at 19:57
add a comment |
You're using Windows XP, so you should have Windows Scripting Host installed by default. With that being said, here's a WSH JScript script to do what you need. Just copy the code to a file name xtract.bat or something along those lines (Can be whatever as long as it has the extension .bat
), and run:
xtract.bat example.tar.gz
By default, the script will check the folder of the script, as well as your system's PATH
environment variable for 7z.exe. If you want to change how it looks for stuff, you can change the SevenZipExe variable at the top of the script to whatever you want the executable name to be. (For instance, 7za.exe or 7z-real.exe) You can also set a default directory for the executable by changing SevenZipDir. So if 7z.exe
is at C:Windowssystem327z.exe
, you'd put:
var SevenZipDir = "C:\Windows\system32";
Anyways, here's the script:
@set @junk=1 /* vim:set ft=javascript:
@echo off
cscript //nologo //e:jscript "%~dpn0.bat" %*
goto :eof
*/
/* Settings */
var SevenZipDir = undefined;
var SevenZipExe = "7z.exe";
var ArchiveExts = ["zip", "tar", "gz", "bzip", "bz", "tgz", "z", "7z", "bz2", "rar"]
/* Multi-use instances */
var WSH = new ActiveXObject("WScript.Shell");
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var __file__ = WScript.ScriptFullName;
var __dir__ = FSO.GetParentFolderName(__file__);
var PWD = WSH.CurrentDirectory;
/* Prototypes */
(function(obj) {
obj.has = function object_has(key) {
return defined(this[key]);
};
return obj;
})(this.Object.prototype);
(function(str) {
str.trim = function str_trim() {
return this.replace(/^ss*/, '').replace(/ss*$/, '');
};
})(this.String.prototype);
(function(arr) {
arr.contains = function arr_contains(needle) {
for (var i in this) {
if (this[i] == needle) {
return true;
}
}
return false;
}
})(this.Array.prototype);
/* Utility functions */
function defined(obj)
{
return typeof(obj) != "undefined";
}
function emptyStr(obj)
{
return !(defined(obj) && String(obj).length);
}
/* WSH-specific Utility Functions */
function echo()
{
if(!arguments.length) return;
var msg = "";
for (var n = 0; n < arguments.length; n++) {
msg += arguments[n];
msg += " ";
}
if(!emptyStr(msg))
WScript.Echo(msg);
}
function fatal(msg)
{
echo("Fatal Error:", msg);
WScript.Quit(1);
}
function findExecutable()
{
// This function searches the directories in;
// the PATH array for the specified file name;
var dirTest = emptyStr(SevenZipDir) ? __dir__ : SevenZipDir;
var exec = SevenZipExe;
var strTestPath = FSO.BuildPath(dirTest, exec);
if (FSO.FileExists(strTestPath))
return FSO.GetAbsolutePathName(strTestPath);
var arrPath = String(
dirTest + ";" +
WSH.ExpandEnvironmentStrings("%PATH%")
).split(";");
for(var i in arrPath) {
// Skip empty directory values, caused by the PATH;
// variable being terminated with a semicolon;
if (arrPath[i] == "")
continue;
// Build a fully qualified path of the file to test for;
strTestPath = FSO.BuildPath(arrPath[i], exec);
// Check if (that file exists;
if (FSO.FileExists(strTestPath))
return FSO.GetAbsolutePathName(strTestPath);
}
return "";
}
function readall(oExec)
{
if (!oExec.StdOut.AtEndOfStream)
return oExec.StdOut.ReadAll();
if (!oExec.StdErr.AtEndOfStream)
return oExec.StdErr.ReadAll();
return -1;
}
function xtract(exec, archive)
{
var splitExt = /^(.+).(w+)$/;
var strTmp = FSO.GetFileName(archive);
WSH.CurrentDirectory = FSO.GetParentFolderName(archive);
while(true) {
var pathParts = splitExt.exec(strTmp);
if(!pathParts) {
echo("No extension detected for", strTmp + ".", "Skipping..");
break;
}
var ext = pathParts[2].toLowerCase();
if(!ArchiveExts.contains(ext)) {
echo("Extension", ext, "not recognized. Skipping.");
break;
}
echo("Extracting", strTmp + "..");
var oExec = WSH.Exec('"' + exec + '" x -bd "' + strTmp + '"');
var allInput = "";
var tryCount = 0;
while (true)
{
var input = readall(oExec);
if (-1 == input) {
if (tryCount++ > 10 && oExec.Status == 1)
break;
WScript.Sleep(100);
} else {
allInput += input;
tryCount = 0;
}
}
if(oExec. ExitCode!= 0) {
echo("Non-zero return code detected.");
break;
}
WScript.Echo(allInput);
strTmp = pathParts[1];
if(!FSO.FileExists(strTmp))
break;
}
WSH.CurrentDirectory = PWD;
}
function printUsage()
{
echo("Usage:rn", __file__, "archive1 [archive2] ...");
WScript.Quit(0);
}
function main(args)
{
var exe = findExecutable();
if(emptyStr(exe))
fatal("Could not find 7zip executable.");
if(!args.length || args(0) == "-h" || args(0) == "--help" || args(0) == "/?")
printUsage();
for (var i = 0; i < args.length; i++) {
var archive = FSO.GetAbsolutePathName(args(i));
if(!FSO.FileExists(archive)) {
echo("File", archive, "does not exist. Skipping..");
continue;
}
xtract(exe, archive);
}
echo("rnDone.");
}
main(WScript.Arguments.Unnamed);
Not that I'm aware of. I initially found it in the following source repository: github.com/ynkdir/winscript It works, because the WSH jscript engine apparently ignores the first bit, up until the comment begins. More information can be found at: stackoverflow.com/questions/4999395/…
– Charles Grunwald
Jun 11 '13 at 1:39
found this: javascriptkit.com/javatutors/conditionalcompile2.shtml which seems to indicate that@set @var = value
is JScript syntax for declaring compile-time variables. So it's both valid JScript and a CMD command
– hdgarrood
Jun 11 '13 at 10:36
add a comment |
You're using Windows XP, so you should have Windows Scripting Host installed by default. With that being said, here's a WSH JScript script to do what you need. Just copy the code to a file name xtract.bat or something along those lines (Can be whatever as long as it has the extension .bat
), and run:
xtract.bat example.tar.gz
By default, the script will check the folder of the script, as well as your system's PATH
environment variable for 7z.exe. If you want to change how it looks for stuff, you can change the SevenZipExe variable at the top of the script to whatever you want the executable name to be. (For instance, 7za.exe or 7z-real.exe) You can also set a default directory for the executable by changing SevenZipDir. So if 7z.exe
is at C:Windowssystem327z.exe
, you'd put:
var SevenZipDir = "C:\Windows\system32";
Anyways, here's the script:
@set @junk=1 /* vim:set ft=javascript:
@echo off
cscript //nologo //e:jscript "%~dpn0.bat" %*
goto :eof
*/
/* Settings */
var SevenZipDir = undefined;
var SevenZipExe = "7z.exe";
var ArchiveExts = ["zip", "tar", "gz", "bzip", "bz", "tgz", "z", "7z", "bz2", "rar"]
/* Multi-use instances */
var WSH = new ActiveXObject("WScript.Shell");
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var __file__ = WScript.ScriptFullName;
var __dir__ = FSO.GetParentFolderName(__file__);
var PWD = WSH.CurrentDirectory;
/* Prototypes */
(function(obj) {
obj.has = function object_has(key) {
return defined(this[key]);
};
return obj;
})(this.Object.prototype);
(function(str) {
str.trim = function str_trim() {
return this.replace(/^ss*/, '').replace(/ss*$/, '');
};
})(this.String.prototype);
(function(arr) {
arr.contains = function arr_contains(needle) {
for (var i in this) {
if (this[i] == needle) {
return true;
}
}
return false;
}
})(this.Array.prototype);
/* Utility functions */
function defined(obj)
{
return typeof(obj) != "undefined";
}
function emptyStr(obj)
{
return !(defined(obj) && String(obj).length);
}
/* WSH-specific Utility Functions */
function echo()
{
if(!arguments.length) return;
var msg = "";
for (var n = 0; n < arguments.length; n++) {
msg += arguments[n];
msg += " ";
}
if(!emptyStr(msg))
WScript.Echo(msg);
}
function fatal(msg)
{
echo("Fatal Error:", msg);
WScript.Quit(1);
}
function findExecutable()
{
// This function searches the directories in;
// the PATH array for the specified file name;
var dirTest = emptyStr(SevenZipDir) ? __dir__ : SevenZipDir;
var exec = SevenZipExe;
var strTestPath = FSO.BuildPath(dirTest, exec);
if (FSO.FileExists(strTestPath))
return FSO.GetAbsolutePathName(strTestPath);
var arrPath = String(
dirTest + ";" +
WSH.ExpandEnvironmentStrings("%PATH%")
).split(";");
for(var i in arrPath) {
// Skip empty directory values, caused by the PATH;
// variable being terminated with a semicolon;
if (arrPath[i] == "")
continue;
// Build a fully qualified path of the file to test for;
strTestPath = FSO.BuildPath(arrPath[i], exec);
// Check if (that file exists;
if (FSO.FileExists(strTestPath))
return FSO.GetAbsolutePathName(strTestPath);
}
return "";
}
function readall(oExec)
{
if (!oExec.StdOut.AtEndOfStream)
return oExec.StdOut.ReadAll();
if (!oExec.StdErr.AtEndOfStream)
return oExec.StdErr.ReadAll();
return -1;
}
function xtract(exec, archive)
{
var splitExt = /^(.+).(w+)$/;
var strTmp = FSO.GetFileName(archive);
WSH.CurrentDirectory = FSO.GetParentFolderName(archive);
while(true) {
var pathParts = splitExt.exec(strTmp);
if(!pathParts) {
echo("No extension detected for", strTmp + ".", "Skipping..");
break;
}
var ext = pathParts[2].toLowerCase();
if(!ArchiveExts.contains(ext)) {
echo("Extension", ext, "not recognized. Skipping.");
break;
}
echo("Extracting", strTmp + "..");
var oExec = WSH.Exec('"' + exec + '" x -bd "' + strTmp + '"');
var allInput = "";
var tryCount = 0;
while (true)
{
var input = readall(oExec);
if (-1 == input) {
if (tryCount++ > 10 && oExec.Status == 1)
break;
WScript.Sleep(100);
} else {
allInput += input;
tryCount = 0;
}
}
if(oExec. ExitCode!= 0) {
echo("Non-zero return code detected.");
break;
}
WScript.Echo(allInput);
strTmp = pathParts[1];
if(!FSO.FileExists(strTmp))
break;
}
WSH.CurrentDirectory = PWD;
}
function printUsage()
{
echo("Usage:rn", __file__, "archive1 [archive2] ...");
WScript.Quit(0);
}
function main(args)
{
var exe = findExecutable();
if(emptyStr(exe))
fatal("Could not find 7zip executable.");
if(!args.length || args(0) == "-h" || args(0) == "--help" || args(0) == "/?")
printUsage();
for (var i = 0; i < args.length; i++) {
var archive = FSO.GetAbsolutePathName(args(i));
if(!FSO.FileExists(archive)) {
echo("File", archive, "does not exist. Skipping..");
continue;
}
xtract(exe, archive);
}
echo("rnDone.");
}
main(WScript.Arguments.Unnamed);
Not that I'm aware of. I initially found it in the following source repository: github.com/ynkdir/winscript It works, because the WSH jscript engine apparently ignores the first bit, up until the comment begins. More information can be found at: stackoverflow.com/questions/4999395/…
– Charles Grunwald
Jun 11 '13 at 1:39
found this: javascriptkit.com/javatutors/conditionalcompile2.shtml which seems to indicate that@set @var = value
is JScript syntax for declaring compile-time variables. So it's both valid JScript and a CMD command
– hdgarrood
Jun 11 '13 at 10:36
add a comment |
You're using Windows XP, so you should have Windows Scripting Host installed by default. With that being said, here's a WSH JScript script to do what you need. Just copy the code to a file name xtract.bat or something along those lines (Can be whatever as long as it has the extension .bat
), and run:
xtract.bat example.tar.gz
By default, the script will check the folder of the script, as well as your system's PATH
environment variable for 7z.exe. If you want to change how it looks for stuff, you can change the SevenZipExe variable at the top of the script to whatever you want the executable name to be. (For instance, 7za.exe or 7z-real.exe) You can also set a default directory for the executable by changing SevenZipDir. So if 7z.exe
is at C:Windowssystem327z.exe
, you'd put:
var SevenZipDir = "C:\Windows\system32";
Anyways, here's the script:
@set @junk=1 /* vim:set ft=javascript:
@echo off
cscript //nologo //e:jscript "%~dpn0.bat" %*
goto :eof
*/
/* Settings */
var SevenZipDir = undefined;
var SevenZipExe = "7z.exe";
var ArchiveExts = ["zip", "tar", "gz", "bzip", "bz", "tgz", "z", "7z", "bz2", "rar"]
/* Multi-use instances */
var WSH = new ActiveXObject("WScript.Shell");
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var __file__ = WScript.ScriptFullName;
var __dir__ = FSO.GetParentFolderName(__file__);
var PWD = WSH.CurrentDirectory;
/* Prototypes */
(function(obj) {
obj.has = function object_has(key) {
return defined(this[key]);
};
return obj;
})(this.Object.prototype);
(function(str) {
str.trim = function str_trim() {
return this.replace(/^ss*/, '').replace(/ss*$/, '');
};
})(this.String.prototype);
(function(arr) {
arr.contains = function arr_contains(needle) {
for (var i in this) {
if (this[i] == needle) {
return true;
}
}
return false;
}
})(this.Array.prototype);
/* Utility functions */
function defined(obj)
{
return typeof(obj) != "undefined";
}
function emptyStr(obj)
{
return !(defined(obj) && String(obj).length);
}
/* WSH-specific Utility Functions */
function echo()
{
if(!arguments.length) return;
var msg = "";
for (var n = 0; n < arguments.length; n++) {
msg += arguments[n];
msg += " ";
}
if(!emptyStr(msg))
WScript.Echo(msg);
}
function fatal(msg)
{
echo("Fatal Error:", msg);
WScript.Quit(1);
}
function findExecutable()
{
// This function searches the directories in;
// the PATH array for the specified file name;
var dirTest = emptyStr(SevenZipDir) ? __dir__ : SevenZipDir;
var exec = SevenZipExe;
var strTestPath = FSO.BuildPath(dirTest, exec);
if (FSO.FileExists(strTestPath))
return FSO.GetAbsolutePathName(strTestPath);
var arrPath = String(
dirTest + ";" +
WSH.ExpandEnvironmentStrings("%PATH%")
).split(";");
for(var i in arrPath) {
// Skip empty directory values, caused by the PATH;
// variable being terminated with a semicolon;
if (arrPath[i] == "")
continue;
// Build a fully qualified path of the file to test for;
strTestPath = FSO.BuildPath(arrPath[i], exec);
// Check if (that file exists;
if (FSO.FileExists(strTestPath))
return FSO.GetAbsolutePathName(strTestPath);
}
return "";
}
function readall(oExec)
{
if (!oExec.StdOut.AtEndOfStream)
return oExec.StdOut.ReadAll();
if (!oExec.StdErr.AtEndOfStream)
return oExec.StdErr.ReadAll();
return -1;
}
function xtract(exec, archive)
{
var splitExt = /^(.+).(w+)$/;
var strTmp = FSO.GetFileName(archive);
WSH.CurrentDirectory = FSO.GetParentFolderName(archive);
while(true) {
var pathParts = splitExt.exec(strTmp);
if(!pathParts) {
echo("No extension detected for", strTmp + ".", "Skipping..");
break;
}
var ext = pathParts[2].toLowerCase();
if(!ArchiveExts.contains(ext)) {
echo("Extension", ext, "not recognized. Skipping.");
break;
}
echo("Extracting", strTmp + "..");
var oExec = WSH.Exec('"' + exec + '" x -bd "' + strTmp + '"');
var allInput = "";
var tryCount = 0;
while (true)
{
var input = readall(oExec);
if (-1 == input) {
if (tryCount++ > 10 && oExec.Status == 1)
break;
WScript.Sleep(100);
} else {
allInput += input;
tryCount = 0;
}
}
if(oExec. ExitCode!= 0) {
echo("Non-zero return code detected.");
break;
}
WScript.Echo(allInput);
strTmp = pathParts[1];
if(!FSO.FileExists(strTmp))
break;
}
WSH.CurrentDirectory = PWD;
}
function printUsage()
{
echo("Usage:rn", __file__, "archive1 [archive2] ...");
WScript.Quit(0);
}
function main(args)
{
var exe = findExecutable();
if(emptyStr(exe))
fatal("Could not find 7zip executable.");
if(!args.length || args(0) == "-h" || args(0) == "--help" || args(0) == "/?")
printUsage();
for (var i = 0; i < args.length; i++) {
var archive = FSO.GetAbsolutePathName(args(i));
if(!FSO.FileExists(archive)) {
echo("File", archive, "does not exist. Skipping..");
continue;
}
xtract(exe, archive);
}
echo("rnDone.");
}
main(WScript.Arguments.Unnamed);
You're using Windows XP, so you should have Windows Scripting Host installed by default. With that being said, here's a WSH JScript script to do what you need. Just copy the code to a file name xtract.bat or something along those lines (Can be whatever as long as it has the extension .bat
), and run:
xtract.bat example.tar.gz
By default, the script will check the folder of the script, as well as your system's PATH
environment variable for 7z.exe. If you want to change how it looks for stuff, you can change the SevenZipExe variable at the top of the script to whatever you want the executable name to be. (For instance, 7za.exe or 7z-real.exe) You can also set a default directory for the executable by changing SevenZipDir. So if 7z.exe
is at C:Windowssystem327z.exe
, you'd put:
var SevenZipDir = "C:\Windows\system32";
Anyways, here's the script:
@set @junk=1 /* vim:set ft=javascript:
@echo off
cscript //nologo //e:jscript "%~dpn0.bat" %*
goto :eof
*/
/* Settings */
var SevenZipDir = undefined;
var SevenZipExe = "7z.exe";
var ArchiveExts = ["zip", "tar", "gz", "bzip", "bz", "tgz", "z", "7z", "bz2", "rar"]
/* Multi-use instances */
var WSH = new ActiveXObject("WScript.Shell");
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var __file__ = WScript.ScriptFullName;
var __dir__ = FSO.GetParentFolderName(__file__);
var PWD = WSH.CurrentDirectory;
/* Prototypes */
(function(obj) {
obj.has = function object_has(key) {
return defined(this[key]);
};
return obj;
})(this.Object.prototype);
(function(str) {
str.trim = function str_trim() {
return this.replace(/^ss*/, '').replace(/ss*$/, '');
};
})(this.String.prototype);
(function(arr) {
arr.contains = function arr_contains(needle) {
for (var i in this) {
if (this[i] == needle) {
return true;
}
}
return false;
}
})(this.Array.prototype);
/* Utility functions */
function defined(obj)
{
return typeof(obj) != "undefined";
}
function emptyStr(obj)
{
return !(defined(obj) && String(obj).length);
}
/* WSH-specific Utility Functions */
function echo()
{
if(!arguments.length) return;
var msg = "";
for (var n = 0; n < arguments.length; n++) {
msg += arguments[n];
msg += " ";
}
if(!emptyStr(msg))
WScript.Echo(msg);
}
function fatal(msg)
{
echo("Fatal Error:", msg);
WScript.Quit(1);
}
function findExecutable()
{
// This function searches the directories in;
// the PATH array for the specified file name;
var dirTest = emptyStr(SevenZipDir) ? __dir__ : SevenZipDir;
var exec = SevenZipExe;
var strTestPath = FSO.BuildPath(dirTest, exec);
if (FSO.FileExists(strTestPath))
return FSO.GetAbsolutePathName(strTestPath);
var arrPath = String(
dirTest + ";" +
WSH.ExpandEnvironmentStrings("%PATH%")
).split(";");
for(var i in arrPath) {
// Skip empty directory values, caused by the PATH;
// variable being terminated with a semicolon;
if (arrPath[i] == "")
continue;
// Build a fully qualified path of the file to test for;
strTestPath = FSO.BuildPath(arrPath[i], exec);
// Check if (that file exists;
if (FSO.FileExists(strTestPath))
return FSO.GetAbsolutePathName(strTestPath);
}
return "";
}
function readall(oExec)
{
if (!oExec.StdOut.AtEndOfStream)
return oExec.StdOut.ReadAll();
if (!oExec.StdErr.AtEndOfStream)
return oExec.StdErr.ReadAll();
return -1;
}
function xtract(exec, archive)
{
var splitExt = /^(.+).(w+)$/;
var strTmp = FSO.GetFileName(archive);
WSH.CurrentDirectory = FSO.GetParentFolderName(archive);
while(true) {
var pathParts = splitExt.exec(strTmp);
if(!pathParts) {
echo("No extension detected for", strTmp + ".", "Skipping..");
break;
}
var ext = pathParts[2].toLowerCase();
if(!ArchiveExts.contains(ext)) {
echo("Extension", ext, "not recognized. Skipping.");
break;
}
echo("Extracting", strTmp + "..");
var oExec = WSH.Exec('"' + exec + '" x -bd "' + strTmp + '"');
var allInput = "";
var tryCount = 0;
while (true)
{
var input = readall(oExec);
if (-1 == input) {
if (tryCount++ > 10 && oExec.Status == 1)
break;
WScript.Sleep(100);
} else {
allInput += input;
tryCount = 0;
}
}
if(oExec. ExitCode!= 0) {
echo("Non-zero return code detected.");
break;
}
WScript.Echo(allInput);
strTmp = pathParts[1];
if(!FSO.FileExists(strTmp))
break;
}
WSH.CurrentDirectory = PWD;
}
function printUsage()
{
echo("Usage:rn", __file__, "archive1 [archive2] ...");
WScript.Quit(0);
}
function main(args)
{
var exe = findExecutable();
if(emptyStr(exe))
fatal("Could not find 7zip executable.");
if(!args.length || args(0) == "-h" || args(0) == "--help" || args(0) == "/?")
printUsage();
for (var i = 0; i < args.length; i++) {
var archive = FSO.GetAbsolutePathName(args(i));
if(!FSO.FileExists(archive)) {
echo("File", archive, "does not exist. Skipping..");
continue;
}
xtract(exe, archive);
}
echo("rnDone.");
}
main(WScript.Arguments.Unnamed);
edited Dec 14 '16 at 5:13
phuclv
9,99164093
9,99164093
answered Nov 26 '11 at 5:34
Charles GrunwaldCharles Grunwald
1593
1593
Not that I'm aware of. I initially found it in the following source repository: github.com/ynkdir/winscript It works, because the WSH jscript engine apparently ignores the first bit, up until the comment begins. More information can be found at: stackoverflow.com/questions/4999395/…
– Charles Grunwald
Jun 11 '13 at 1:39
found this: javascriptkit.com/javatutors/conditionalcompile2.shtml which seems to indicate that@set @var = value
is JScript syntax for declaring compile-time variables. So it's both valid JScript and a CMD command
– hdgarrood
Jun 11 '13 at 10:36
add a comment |
Not that I'm aware of. I initially found it in the following source repository: github.com/ynkdir/winscript It works, because the WSH jscript engine apparently ignores the first bit, up until the comment begins. More information can be found at: stackoverflow.com/questions/4999395/…
– Charles Grunwald
Jun 11 '13 at 1:39
found this: javascriptkit.com/javatutors/conditionalcompile2.shtml which seems to indicate that@set @var = value
is JScript syntax for declaring compile-time variables. So it's both valid JScript and a CMD command
– hdgarrood
Jun 11 '13 at 10:36
Not that I'm aware of. I initially found it in the following source repository: github.com/ynkdir/winscript It works, because the WSH jscript engine apparently ignores the first bit, up until the comment begins. More information can be found at: stackoverflow.com/questions/4999395/…
– Charles Grunwald
Jun 11 '13 at 1:39
Not that I'm aware of. I initially found it in the following source repository: github.com/ynkdir/winscript It works, because the WSH jscript engine apparently ignores the first bit, up until the comment begins. More information can be found at: stackoverflow.com/questions/4999395/…
– Charles Grunwald
Jun 11 '13 at 1:39
found this: javascriptkit.com/javatutors/conditionalcompile2.shtml which seems to indicate that
@set @var = value
is JScript syntax for declaring compile-time variables. So it's both valid JScript and a CMD command– hdgarrood
Jun 11 '13 at 10:36
found this: javascriptkit.com/javatutors/conditionalcompile2.shtml which seems to indicate that
@set @var = value
is JScript syntax for declaring compile-time variables. So it's both valid JScript and a CMD command– hdgarrood
Jun 11 '13 at 10:36
add a comment |
As you can see 7-Zip is not very good at this. People have been asking for
tarball atomic operation since 2009. Here is a small program
(490 KB) in Go that can do it, I compiled it for you.
package main
import (
"archive/tar"
"compress/gzip"
"flag"
"fmt"
"io"
"os"
"strings"
)
func main() {
flag.Parse() // get the arguments from command line
sourcefile := flag.Arg(0)
if sourcefile == "" {
fmt.Println("Usage : go-untar sourcefile.tar.gz")
os.Exit(1)
}
file, err := os.Open(sourcefile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer file.Close()
var fileReader io.ReadCloser = file
// just in case we are reading a tar.gz file,
// add a filter to handle gzipped file
if strings.HasSuffix(sourcefile, ".gz") {
if fileReader, err = gzip.NewReader(file); err != nil {
fmt.Println(err)
os.Exit(1)
}
defer fileReader.Close()
}
tarBallReader := tar.NewReader(fileReader)
// Extracting tarred files
for {
header, err := tarBallReader.Next()
if err != nil {
if err == io.EOF {
break
}
fmt.Println(err)
os.Exit(1)
}
// get the individual filename and extract to the current directory
filename := header.Name
switch header.Typeflag {
case tar.TypeDir:
// handle directory
fmt.Println("Creating directory :", filename)
// or use 0755 if you prefer
err = os.MkdirAll(filename, os.FileMode(header.Mode))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case tar.TypeReg:
// handle normal file
fmt.Println("Untarring :", filename)
writer, err := os.Create(filename)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
io.Copy(writer, tarBallReader)
err = os.Chmod(filename, os.FileMode(header.Mode))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
writer.Close()
default:
fmt.Printf("Unable to untar type : %c in file %s", header.Typeflag,
filename)
}
}
}
add a comment |
As you can see 7-Zip is not very good at this. People have been asking for
tarball atomic operation since 2009. Here is a small program
(490 KB) in Go that can do it, I compiled it for you.
package main
import (
"archive/tar"
"compress/gzip"
"flag"
"fmt"
"io"
"os"
"strings"
)
func main() {
flag.Parse() // get the arguments from command line
sourcefile := flag.Arg(0)
if sourcefile == "" {
fmt.Println("Usage : go-untar sourcefile.tar.gz")
os.Exit(1)
}
file, err := os.Open(sourcefile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer file.Close()
var fileReader io.ReadCloser = file
// just in case we are reading a tar.gz file,
// add a filter to handle gzipped file
if strings.HasSuffix(sourcefile, ".gz") {
if fileReader, err = gzip.NewReader(file); err != nil {
fmt.Println(err)
os.Exit(1)
}
defer fileReader.Close()
}
tarBallReader := tar.NewReader(fileReader)
// Extracting tarred files
for {
header, err := tarBallReader.Next()
if err != nil {
if err == io.EOF {
break
}
fmt.Println(err)
os.Exit(1)
}
// get the individual filename and extract to the current directory
filename := header.Name
switch header.Typeflag {
case tar.TypeDir:
// handle directory
fmt.Println("Creating directory :", filename)
// or use 0755 if you prefer
err = os.MkdirAll(filename, os.FileMode(header.Mode))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case tar.TypeReg:
// handle normal file
fmt.Println("Untarring :", filename)
writer, err := os.Create(filename)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
io.Copy(writer, tarBallReader)
err = os.Chmod(filename, os.FileMode(header.Mode))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
writer.Close()
default:
fmt.Printf("Unable to untar type : %c in file %s", header.Typeflag,
filename)
}
}
}
add a comment |
As you can see 7-Zip is not very good at this. People have been asking for
tarball atomic operation since 2009. Here is a small program
(490 KB) in Go that can do it, I compiled it for you.
package main
import (
"archive/tar"
"compress/gzip"
"flag"
"fmt"
"io"
"os"
"strings"
)
func main() {
flag.Parse() // get the arguments from command line
sourcefile := flag.Arg(0)
if sourcefile == "" {
fmt.Println("Usage : go-untar sourcefile.tar.gz")
os.Exit(1)
}
file, err := os.Open(sourcefile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer file.Close()
var fileReader io.ReadCloser = file
// just in case we are reading a tar.gz file,
// add a filter to handle gzipped file
if strings.HasSuffix(sourcefile, ".gz") {
if fileReader, err = gzip.NewReader(file); err != nil {
fmt.Println(err)
os.Exit(1)
}
defer fileReader.Close()
}
tarBallReader := tar.NewReader(fileReader)
// Extracting tarred files
for {
header, err := tarBallReader.Next()
if err != nil {
if err == io.EOF {
break
}
fmt.Println(err)
os.Exit(1)
}
// get the individual filename and extract to the current directory
filename := header.Name
switch header.Typeflag {
case tar.TypeDir:
// handle directory
fmt.Println("Creating directory :", filename)
// or use 0755 if you prefer
err = os.MkdirAll(filename, os.FileMode(header.Mode))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case tar.TypeReg:
// handle normal file
fmt.Println("Untarring :", filename)
writer, err := os.Create(filename)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
io.Copy(writer, tarBallReader)
err = os.Chmod(filename, os.FileMode(header.Mode))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
writer.Close()
default:
fmt.Printf("Unable to untar type : %c in file %s", header.Typeflag,
filename)
}
}
}
As you can see 7-Zip is not very good at this. People have been asking for
tarball atomic operation since 2009. Here is a small program
(490 KB) in Go that can do it, I compiled it for you.
package main
import (
"archive/tar"
"compress/gzip"
"flag"
"fmt"
"io"
"os"
"strings"
)
func main() {
flag.Parse() // get the arguments from command line
sourcefile := flag.Arg(0)
if sourcefile == "" {
fmt.Println("Usage : go-untar sourcefile.tar.gz")
os.Exit(1)
}
file, err := os.Open(sourcefile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer file.Close()
var fileReader io.ReadCloser = file
// just in case we are reading a tar.gz file,
// add a filter to handle gzipped file
if strings.HasSuffix(sourcefile, ".gz") {
if fileReader, err = gzip.NewReader(file); err != nil {
fmt.Println(err)
os.Exit(1)
}
defer fileReader.Close()
}
tarBallReader := tar.NewReader(fileReader)
// Extracting tarred files
for {
header, err := tarBallReader.Next()
if err != nil {
if err == io.EOF {
break
}
fmt.Println(err)
os.Exit(1)
}
// get the individual filename and extract to the current directory
filename := header.Name
switch header.Typeflag {
case tar.TypeDir:
// handle directory
fmt.Println("Creating directory :", filename)
// or use 0755 if you prefer
err = os.MkdirAll(filename, os.FileMode(header.Mode))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
case tar.TypeReg:
// handle normal file
fmt.Println("Untarring :", filename)
writer, err := os.Create(filename)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
io.Copy(writer, tarBallReader)
err = os.Chmod(filename, os.FileMode(header.Mode))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
writer.Close()
default:
fmt.Printf("Unable to untar type : %c in file %s", header.Typeflag,
filename)
}
}
}
answered Oct 29 '16 at 18:37
Steven PennySteven Penny
1
1
add a comment |
add a comment |
7za is work properly as below:
7za.exe x D:pkg-tempProd-Rtx-Service.tgz -so | 7za.exe x -si -ttar -oD:pkg-tempProd-Rtx-Service
3
Can you add some context around how this command works? Please see How to Answer and take our tour.
– Burgi
Aug 31 '18 at 9:08
add a comment |
7za is work properly as below:
7za.exe x D:pkg-tempProd-Rtx-Service.tgz -so | 7za.exe x -si -ttar -oD:pkg-tempProd-Rtx-Service
3
Can you add some context around how this command works? Please see How to Answer and take our tour.
– Burgi
Aug 31 '18 at 9:08
add a comment |
7za is work properly as below:
7za.exe x D:pkg-tempProd-Rtx-Service.tgz -so | 7za.exe x -si -ttar -oD:pkg-tempProd-Rtx-Service
7za is work properly as below:
7za.exe x D:pkg-tempProd-Rtx-Service.tgz -so | 7za.exe x -si -ttar -oD:pkg-tempProd-Rtx-Service
answered Aug 31 '18 at 8:08
Alan HuAlan Hu
1
1
3
Can you add some context around how this command works? Please see How to Answer and take our tour.
– Burgi
Aug 31 '18 at 9:08
add a comment |
3
Can you add some context around how this command works? Please see How to Answer and take our tour.
– Burgi
Aug 31 '18 at 9:08
3
3
Can you add some context around how this command works? Please see How to Answer and take our tour.
– Burgi
Aug 31 '18 at 9:08
Can you add some context around how this command works? Please see How to Answer and take our tour.
– Burgi
Aug 31 '18 at 9:08
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f80019%2fhow-can-i-unzip-a-tar-gz-in-one-step-using-7-zip%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown