I try to unzip a file via CMD.
So I install winzip (and its plugin to cmd), winrar and 7-zip.
But when I try to execute a command via the CMD:
7z e myzip.zip
It gives the next error:
7z is not recognized as an internal or external command
In addition, I added the folder of 7-z to the environment variables (Properties--> advanced --> Environment Variables --> user variable --> choose path, and add C:\Program Files\7-Zip
What can be the reason?
Doing the following in a command prompt works for me, also adding to my User environment variables worked fine as well:
set PATH=%PATH%;C:\Program Files\7-Zip\
echo %PATH%
7z
You should see as output (or something similar - as this is on my laptop running Windows 7):
C:\Users\Phillip>set PATH=%PATH%;C:\Program Files\7-Zip\
C:\Users\Phillip>echo %PATH%
C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Wi
ndows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\
WirelessCommon\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\To
ols\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Fil
es (x86)\QuickTime\QTSystem\;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Notepad+
+;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\7-Zip\
C:\Users\Phillip>7z
7-Zip [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
[<#listfiles...>]
<Commands>
a: Add files to archive
b: Benchmark
d: Delete files from archive
e: Extract files from archive (without using directory names)
l: List contents of archive
t: Test integrity of archive
u: Update files to archive
x: eXtract files with full paths
<Switches>
-ai[r[-|0]]{#listfile|!wildcard}: Include archives
-ax[r[-|0]]{#listfile|!wildcard}: eXclude archives
-bd: Disable percentage indicator
-i[r[-|0]]{#listfile|!wildcard}: Include filenames
-m{Parameters}: set compression Method
-o{Directory}: set Output directory
-p{Password}: set Password
-r[-|0]: Recurse subdirectories
-scs{UTF-8 | WIN | DOS}: set charset for list files
-sfx[{name}]: Create SFX archive
-si[{name}]: read data from stdin
-slt: show technical information for l (List) command
-so: write data to stdout
-ssc[-]: set sensitive case mode
-ssw: compress shared files
-t{Type}: Set type of archive
-u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options
-v{Size}[b|k|m|g]: Create volumes
-w[{path}]: assign Work directory. Empty path means a temporary directory
-x[r[-|0]]]{#listfile|!wildcard}: eXclude filenames
-y: assume Yes on all queries
Regarding Phil Street's post:
It may actually be installed in your 32-bit program folder instead of your default x64, if you're running 64-bit OS. Check to see where 7-zip is installed, and if it is in Program Files (x86) then try using this instead:
PATH=%PATH%;C:\Program Files (x86)\7-Zip
make sure that your path is pointing to .exe file in C:\Program Files\7-Zip (may in bin directory)
In Windows 10 I had to run the batch file as an administrator.
Related
I need to loop over a lot of jar files to delete previous signs and remake the sign for each jar so I make this script for windows, it works well but it stops when a 'Warning' message appears; and I have to click 'close' a lot of times. The warning is because "no file was found to delete".
#echo off
REM iterate over jar files in path
for %%x in (C:\My\Path\to\jar\files\*.jar) do (
echo Jar name: %%~nx
echo -------------------------------------
REM delete previous signatures
"C:\Program Files\WinRAR\WinRAR.exe" d %%x *.RSA *.SF
REM execute sign command
C:\My\Path\To\jarsigner.exe -keystore C:\My\Path\to\mykeystore.jks -storepass myStorepassKey -keypass myKeyspassKey %%x keys_alias
)
Since you are editing a .jar file, which is inherently a zip file, you can avoid using WinRAR.
The zip command provides methods to delete entries in a zip file. also, if you have 7zip installed, which is available in Windows, 7z d archive.jar *.RSA -r might do the trick.
See also: How to delete a file from multiple zip archives using 7-Zip
If I do C:\Program Files\WinRAR\rar.exe /?
I get all the commands and switches, which means you should rather use rar to run:
"C:\Program Files\WinRAR\rar" d %%x *.RSA *.SF
Jar files are effectively zipped files.
help output:
<Commands>
a Add files to archive
c Add archive comment
ch Change archive parameters
cw Write archive comment to file
d Delete files from archive
e Extract files without archived paths
f Freshen files in archive
i[par]=<str> Find string in archives
k Lock archive
l[t[a],b] List archive contents [technical[all], bare]
m[f] Move to archive [files only]
p Print file to stdout
r Repair archive
rc Reconstruct missing volumes
rn Rename archived files
rr[N] Add data recovery record
rv[N] Create recovery volumes
s[name|-] Convert archive to or from SFX
t Test archive files
u Update files in archive
v[t[a],b] Verbosely list archive contents [technical[all],bare]
x Extract files with full path
You can use -inul option. And the -o+ (force overwrite) or -o- (don't overwrite) options might help as well during extraction.
So I am trying to create a batch file to automatically import SSL certificates into the Java keystore, cacerts. I'm trying to copy all the .crt files into:
C:\Program Files\Java\jre*\lib\security
This way I can then use keytool to import them. The issue is that the copy command won't let me use jre* to specify the jre directory, and then version. I want to make the batch so that it will work across multiple PCs with the Java install at C:\Program Files\Java (the default directory), but across multiple versions of the Java jre.
Thanks!
Wildcards like * and ? can only be used for the very last element of a path.
You may use the following work-around to achieve what you want (assuming there is only one matching directory):
in command prompt (cmd):
for /D %D in ("C:\Program Files\Java\jre*") do #set "FOUNDDIR=%~fD\lib\security"
echo Found directory: "%FOUNDDIR%"
within a batch file:
for /D %%D in ("C:\Program Files\Java\jre*") do set "FOUNDDIR=%%~fD\lib\security"
echo Found directory: "%FOUNDDIR%"
The Problem
When I enter the command android in the normal Windows command prompt, android.bat is launched from the a directory I included in the PATH-variable.
When I enter the same command in the msysgit Git Bash, the bash complains:
sh.exe": android: command not found
android is the only command that has this problem, all others work on both shells (the directory it is contained in is android-sdk/tools )
Working examples are node, npm, heroku.
My environment
This is what echo $PATH returns in Git Bash:
/c/Users/Tobias/bin:.:/usr/local/bin:/mingw/bin:/bin:/c/Users/Tobias/AppData/Local/apache-ant-1.9.4/bin:/cmd:/c/Program Files/nodejs/:/c/Python27:/c/Python34/:/c/Python34/Scripts:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/c/Program Files (x86)/ATI Technologies/ATI.ACE/Core-Static:/c/Program Files (x86)/Common Files/Acronis/SnapAPI/:/c/Program Files (x86)/Heroku/bin:/c/Program Files/Java/jdk1.8.0_11/bin:/c/Ruby200-x64/bin:/c/Users/Tobias/AppData/Roaming/npm:/c/Users/Tobias/AppData/Local/Android/android-sdk/tools:/c/Users/Tobias/AppData/Local/Android/android-sdk/platform-tools:.
This is what echo %PATH% returns in Windows CMD:
C:\Users\Tobias\AppData\Local\apache-ant-1.9.4\bin;C:\Program Files (x86)\git\cmd;C: \Program Files\nodejs\;C:\Python27;C:\Python34\;C:\Python34\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Common Files\Acronis\SnapAPI\;C:\Program Files (x86)\Heroku\bin;C:\Program Files\Java\jdk1.8.0_11\bin;C:\Ruby200-x64\bin;C:\Users\Tobias\AppData\Roaming\npm;C:\Users\Tobias\AppData\Local\Android\android-sdk\tools;C:\Users\Tobias\AppData\Local\Android\android-sdk\platform-tools;
Seems like msysgit can't access files inside C:\Users\x\AppData\Roaming.
I fixed the issue by moving the directory directly in the C: drive.
I want to zip a directory using the batch file command (Windows XP batch file).
For example, if I want to unzip a file means I can use the jar -xf file.zip(java) bat file command.
Like that I want a command line batch to zip a directory.
If you are using Ubuntu Linux:
Install zip
sudo apt-get install zip
Zip your folder:
zip -r {filename.zip} {foldername}
If you are using Microsoft Windows:
Windows does not come with a command-line zip program, despite Windows Explorer natively supporting Zip files since the Plus! pack for Windows 98.
I recommend the open-source 7-Zip utility which includes a command-line executable and supports many different archive file types, especially its own *.7z format which offers superior compression ratios to traditional (PKZIP) *.zip files:
Download 7-Zip from the 7-Zip home page
Add the path to 7z.exe to your PATH environment variable. See this QA:
How to set the path and environment variables in Windows
Open a new command-prompt window and use this command to create a PKZIP *.zip file:
7z a -tzip {yourfile.zip} {yourfolder}
Cross-platform Java:
If you have the Java JDK installed then you can use the jar utility to create Zip files, as *.jar files are essentially just renamed *.zip (PKZIP) files:
jar -cfM {yourfile.zip} {yourfolder}
Explanation:
* -c compress
* -f specify filename
* -M do not include a MANIFEST file
Yes, we can zip and unzip the file/folder using cmd. See the below command and simply you can copy past in cmd and change the directory and file name
To Zip/Compress File
powershell Compress-Archive D:\Build\FolderName D:\Build\FolderName.zip
To Unzip/Expand File
powershell expand-archive D:\Build\FileName.zip D:\deployments\FileName
You can use the following command:
zip -r nameoffile.zip directory
Hope this helps.
Windows 10 has tar command since 2018. It supports zip archive in default. You do not need to install any additional packages nor software.
tar.exe acvf yourfile.zip yourfolder
Compress-Archive in PowerShell does not support 2GB+ files.
The zip Package should be installed in system.
To Zip a File
zip <filename.zip> <file>
Example:
zip doc.zip doc.txt
To Unzip a File
unzip <filename.zip>
Example:
unzip mydata.zip
Zip the folder from cmd by running PowerShell:
powershell "Add-Type -A System.IO.Compression.FileSystem; [IO.Compression.ZipFile]::CreateFromDirectory('folder','archive.zip')"
Unzip:
powershell "Add-Type -A System.IO.Compression.FileSystem; [IO.Compression.ZipFile]::ExtractToDirectory('archive.zip','folder')"
Nothing listed here worked with me. This should be a very simple thing. I post my answer here, if anything because each time I search for "how to zip on the cmd window" I end up on this page, with no solution that works for me.
So here is the one that works with me: zip output_file input_files, as in the screenshot below.
Using Microsoft's NMAKE with -I option to for include paths. It works for the include files in these folders, but can't seem to find one in a named subfolder:
Here's the resulting command & error message:
cl /nologo /Ox /MD /EHsc /W3 /D_CRT_SECURE_NO_DEPRECATE -I "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\sys"; -I. "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\sys" "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include" "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include" -DAVOID_WIN32_FILEIO -DCHECK_JPEG_YCBCR_SUBSAMPLING -DDEFAULT_EXTRASAMPLE_AS_ALPHA -DSTRIPCHOP_DEFAULT=TIFF_STRIPCHOP -DSTRIP_SIZE_DEFAULT=8192 -DLOGLUV_SUPPORT -DNEXT_SUPPORT -DTHUNDER_SUPPORT -DLZW_SUPPORT -DPACKBITS_SUPPORT -DCCITT_SUPPORT -DTIF_PLATFORM_CONSOLE -DFILLODER_LSB2MSB /c tif_unix.c
tif_unix.c
tif_unix.c(35) : fatal error C1083: Cannot open include file: 'sys/types.h': No such file or directory
Two things to note:
The "missing" file, "types.h", IS in the "sys" subfolder of one of the include paths, so "sys/types.h" should have been found, and
The "sys" subfolder was also included (out of desperation) and types.h STILL wasn't found.
Any ideas why this include file can't be found?
It looks like you're not using the option correctly. The syntax is -I directory, and according to the Microsoft documentation, to add more than one directory, you must use this option more than once. If you have faithfully reproduced the actual command-line you're using, then you have got -I directory -I directory directory directory directory, so several of your include directories are ignored.
Assuming you want all of these directories in the include path, the correct syntax is:
-I "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\sys"
-I.
-I "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\sys"
-I "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include"
-I "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include"
Note the use of -I before each directory, including . .