What does the percent sign (% and %%) in a batch file argument mean?

57,939

The for command needs a placeholder so you can pass along variables for use later in the query, we are telling it use the placeholder %A, the reason the code you saw uses %%A is because inside a batch file (which I assume is where you found this) the % has a special meaning, so you must do it twice %% so it gets turned in to a single % to be passed to the for command

To actually break apart what the command is doing, there is two parts to the command:

 for /D %%A in (*) do .....

What this part says is for every folder in the current folder execute the following command replacing %%A with the name of the currently processing folder.

..... "\7za.exe" u -t7z -m9=LZMA2 "%%A.7z" "%%A"

What this part says is execute the command "\7za.exe" u -t7z -m9=LZMA2 "%%A.7z" "%%A" and replace the two %%A's with the current record we are processing.

Share:
57,939

Related videos on Youtube

Jim Kieger
Author by

Jim Kieger

Updated on September 18, 2022

Comments

  • Jim Kieger
    Jim Kieger over 1 year

    I think I'm missing something because I can't seem to find what this means.

    Example:

    for /D %%A in (*) do "\7za.exe" u -t7z -m9=LZMA2 "%%A.7z" "%%A"
    

    That line was supposed to use a command line version of 7zip to compress individual folders, but I'm stumped as to what %%A means in this context.

  • Nullpointer42
    Nullpointer42 over 10 years
    Just to nitpick - the /D on the for loop will limit the * wildcard to directories, not "every file in this folder and every subfolder" (assuming Command Extensions are enabled).
  • Scott Chamberlain
    Scott Chamberlain over 10 years
    @ernie you are correct, I was looking at the /R switch on the help page, I have corrected my answer.
  • Jim Kieger
    Jim Kieger over 10 years
    Thank you for that, it shows how noobish this seems, but it's pretty archaic stuff that I have to dig through a couple online manuals for.