87

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?

user4157124
  • 2,809
  • 13
  • 27
  • 42
Adam Sh
  • 8,137
  • 22
  • 60
  • 75

4 Answers4

135

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
Phil Street
  • 2,735
  • 2
  • 20
  • 25
  • 14
    to avoid having to do this for each session, you can use setx instead: `setx PATH "%PATH%;C:\Program Files\7-Zip\"`. Then restart your CMD (or use the original set command to set it for the current session too) – Ewout Jan 27 '16 at 10:05
  • @Ewout For me, this proved for the first time "for sure" that adding to `PATH` generally means adding to the `user path`, not to the `system path`, as the `setx` is adding to the `user path`. It might be clear to everyone, I did not know it even after dozens of times changing the `environmental variables`. – questionto42 Aug 19 '20 at 10:54
  • 1
    My 7zip folder includes an Uninstall.exe, it will make this visible to the path too I assume, as well as 7zFM and 7zG. I would recommend you to isolate the command line tool from those other ones. – AgentM Aug 31 '21 at 17:43
8

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
ataravati
  • 8,891
  • 9
  • 57
  • 89
mike
  • 81
  • 1
  • 1
1

make sure that your path is pointing to .exe file in C:\Program Files\7-Zip (may in bin directory)

shreyas
  • 1,360
  • 11
  • 11
  • 3
    No, it should point to "C:\Program Files\7-Zip" folder. System will then read all the "exe" files from there and make it available to the command line (make sure to close the current command lines and start a new ones because changes aren't available until restart of those command lines). – Beemo Jul 26 '17 at 07:50
0

In Windows 10 I had to run the batch file as an administrator.

Ulysses Alves
  • 2,297
  • 3
  • 24
  • 34