FOR parameters

Microsoft Windows
Post Reply
legirio
Posts: 1
Joined: 2022-Sep-15, 12:22 pm

FOR parameters

Post by legirio »

Can anyone help me with this command, I used this command below in 2017, but now it doesn't work anymore, could you tell me what could be wrong with this command line.
This command does the following, it compresses all folders individually, generating a ZIP for each folder.

for /d %%X in ("F:\client_1\"*) do "C:\Program Files\7-Zip\7z.exe" a "%%X.zip" "%%X\*" -sdel


Windows 2012 x64
User avatar
Simon Sheppard
Posts: 190
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: FOR parameters

Post by Simon Sheppard »

To troubleshoot this you could try putting an ECHO before the "C:\Program Files\7-Zip\7z.exe"
so you can see what it is passing to 7z.

I don't think you need that asterisk after the "F:\client_1\"
Clif_McIrvin
Posts: 2
Joined: 2022-Sep-16, 10:59 pm

Re: FOR parameters

Post by Clif_McIrvin »

I'm thinking cmd.exe has recently broken. I also have a script that has been working for years that is now broken. The following code snippet no longer generates the correct output - so when using similar syntax to construct a REN command (for instance) the script is useless. Unfortunately I cannot backtrack to when it last worked. Currently running Windows 10 Enterprise for Virtual Desktops 21H1 19043 1889; also getting same results on Windows 10 Pro 21H2 19044 1889.

Code: Select all

for %%f in (*) do (
echo %%f quoted "abcd"
echo %%f quoted "abcd" %%f
echo %%f quoted "abcd" "%%f"
echo quoted "%%f" "!_to:%_shortcut%=!"
pause )
User avatar
Simon Sheppard
Posts: 190
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: FOR parameters

Post by Simon Sheppard »

If you are testing the snippet at the command line, you will need to change the %%f to just %f
Clif_McIrvin
Posts: 2
Joined: 2022-Sep-16, 10:59 pm

Re: FOR parameters

Post by Clif_McIrvin »

Simon thank you for responding.
A couple things ... I fumbled my code snippet and left out two critical lines. :oops:
The snippet was in fact running AFTER setlocal enabledelayedexpansion.
The problem was caused by an exclamation mark ( ! ) in a filename.
I missed seeing the problem because of @echo off at the beginning of my test script.
While I'm new to the forum I've used ss64.com for years, and once again you came through for me.
Thank you for your work in building and maintaining ss64.com.
Post Reply