-3

I created the file extract.bat with the code:

@echo off

7z x "f:\Downloads\*.zip" –o"f:\Downloads"
7z x "f:\Downloads\*.rar" –o"f:\Downloads"
7z x "f:\Downloads\*.7z" –o"f:\Downloads"

pause

If I open the cmd and run the code:

7z x "f:\Downloads\*.zip" –o"f:\Downloads"

It works, but if I open the .BAT file, the zip isn't extracted.

Why???

Thank you!

Update: Output after run extract.bat:

F:\Programas>7z x "F:\Downloads\*.zip" ΓÇôo"f:\Downloads"

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive for archives:
1 file, 731338124 bytes (698 MiB)

Extracting archive: F:\Downloads\PromoVideo[720p].zip
--
Path = F:\Downloads\PromoVideo[720p].zip
Type = zip
Physical Size = 731338124


No files to process
Everything is Ok

Files: 0
Size:       0
Compressed: 731338124

F:\Programas>pause
Press any key to continue . . .

and output after run the command directly into cmd:

Microsoft Windows [Version 10.0.18362.900]
(c) 2019 Microsoft Corporation. All rights reserved.

C:\Users\Diego>7z x "F:\Downloads\*.zip" -o"f:\Downloads"

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive for archives:
1 file, 731338124 bytes (698 MiB)

Extracting archive: F:\Downloads\PromoVideo[720p].zip
--
Path = F:\Downloads\PromoVideo[720p].zip
Type = zip
Physical Size = 731338124

Everything is Ok

Size:       731544885
Compressed: 731338124

C:\Users\Diego>

As you can see, if i run the command:

7z x "F:\Downloads\*.zip" –o"f:\Downloads"

Directly into cmd it works, but it don't work if i open the .BAT file.

Any idea, pls?

Thank you!

  • Did you add the 7zip path to the %path% variable? – Ricardo Bohner Jul 11 '20 at 21:18
  • @RicardoBohner yes, i added. it shows up some info about 7zip, but dont extract the file from bat file. Any idea? ty!!! – user3790692 Jul 11 '20 at 21:39
  • 5
    @user3790692 Comment out the `@echo off` line and post the complete output, including the `7z` output. Are both the batch file and cmd line executed at the same prompt? – dxiv Jul 11 '20 at 21:44
  • Does this work `for %%a in (*.zip) do (7z x "F:\Downloads\%%~fa" -o"F:\Downloads")` – Wasif Jul 12 '20 at 01:57
  • @dxiv I updated the post with the output. Thank you for help. – user3790692 Jul 12 '20 at 03:16
  • @Wasif_Hasan it dont work. Nothing happens. I think its because the .bat file is at folder: F:\Programas instead F:\Downloads . btw thank you for ur help. – user3790692 Jul 12 '20 at 03:16

1 Answers1

1

The .bat file echo'd:

F:\Programas>7z x "F:\Downloads\*.zip" ΓÇôo"f:\Downloads"

ΓÇô in OEM codepage 437 is hex bytes E2 80 93, which represent the en-dash in UTF-8 encoding. But 7z expects a plain dash -o switch, so it does not recognize ΓÇôo (or even an en-dash –o) as a switch.

To fix the issue, make sure to:

  • use a plain - dash in the .bat file (not any other fancy character that may look like a dash);

  • save the .bat file as plain text (not UTF-8).

dxiv
  • 16,984
  • 2
  • 27
  • 49