Is it possible to escape characters from the source file or archive when using 7-zip's command line interface. For example:

7z a "My%Archive.zip" "My%File.txt" -mx9

This command line fails at both creating the correct archive and choosing the correct file to zip. I would like to know how to escape the percent (%) character.


If the files don't actually have a percent symbol in them, you don't need to add one:

7z a "My Archive.zip" "My File.txt" -mx9

if you're unsure on how to type a file name, type the first few letters of the file's name then press tab for auto-completion. Keep in mind though you must type enough letters of the file's name to uniquely identify it, or you will have to press tab multiple times and cycle through other files that have the same beginning letters.

  • The source file does have a % symbol. Also, I want a percent in the archive name so it matches the source file. – Sigray Oct 12 '09 at 22:22
  • what version of windows are you running? – John T Oct 12 '09 at 22:24
  • Windows 7 Ultimate 7-Zip 4.65 – Sigray Oct 12 '09 at 22:25
  • I just tried with the most recent version of 7z. Works with creating the archive when a % symbol is in the filename and archive name as you can see here: i36.tinypic.com/2n7r4wm.jpg can you perform the steps in the command line and show me the output with a screenshot? also include output of the dir command on the directory containing the file you wish to compress. – John T Oct 12 '09 at 22:40
  • Someone just answered my question on SourceForge. I had the commands in a batch file, and it was trying to interpret the % symbols. They need to be escaped with double percent (%%). I will try this tonight and report the results. – Sigray Oct 12 '09 at 22:45

The problem stems from that fact that these commands were being issued from within a batch file. The % symbol has a special meaning in batch files. They can be escaped by doubling up the symbol (%%). Example:

7z a "My%%Archive.zip" "My%%File.txt" -mx9

I also tried to escape with the caret (^) but that did not work.

The percent symbol problem has nothing to do with 7zip.

This question was answered on SourceForge.

SourceForge Thread

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.