Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

%%A was unexpected at this time

I want to zip a folder containing files. So inorder to do that i need to loop through the entire file list and execute 7za command. (7zip command line version)

for /f %%A in ('"G:\Files Sample\zip\txt\*.t xt"') do 7za -tzip "%%A.zip" "%%A" 

However windows says that this command is not valid.

Error message is

%%A was unexpected at this time 

How do i overcome this issue ?

like image 472
klijo Avatar asked Feb 16 '12 12:02

klijo


People also ask

What does %% A mean?

%%a refers to the name of the variable your for loop will write to. Quoted from for /? : FOR %variable IN (set) DO command [command-parameters] %variable Specifies a single letter replaceable parameter. (set) Specifies a set of one or more files. Wildcards may be used.

Was unexpected at this time batch error?

If you are getting this error on your IF statement check if used or not your double equals to compare your variable. Eg. This throws "=1 was unexpected at this time." To correct this add another equals sign.

How do I comment in a batch file?

A batch file can be commented using either two colons :: or a REM command. The main difference is that the lines commented out using the REM command will be displayed during execution of the batch file (can be avoided by setting @echo off ) while the lines commented out using :: , won't be printed.

What is Usebackq?

usebackq. Specifies to run a back-quoted string as a command, use a single-quoted string as a literal string, or, for long file names that contain spaces, allow file names in <set> , to each be enclosed in double-quotation marks.


2 Answers

%%A is used when you use a batch program (*.bat)

try remove one '%'

like image 58
Royi Namir Avatar answered Oct 07 '22 15:10

Royi Namir


If you are doing it from the command line, you don't have to escape the %, so %a is sufficient. You only need to use %%a from batch files.

Also, you wanna be selecting the files instead of executing "G:\Files Sample\zip\txt\*.txt" as a command, which is what the /f switch does in combination with single quotes. The full command would be: for %A in ("G:\Files Sample\zip\txt\*.txt") do 7za -tzip "%A.zip" "%A"

like image 26
aross Avatar answered Oct 07 '22 14:10

aross