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 ?
%%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.
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.
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.
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.
%%A
is used when you use a batch program (*.bat)
try remove one '%'
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With