FG
💻 Software

Windows command line: How to append a variable in a loop?

Fresh7 days ago
Mar 15, 202623282 views
Confidence Score0%
0%

Problem

I'm trying to fill a variable with a space-separated list of files, but I can't quite seem to get my head around it. Here's what I have so far: I would have expected this to keep appending the variable with the next filename, but instead it replaces the whole variable: I see in the second line of o…

Error Output

set js_files=
for %%f in (js/*.js) do set js_files=%js_files% js/%%f
echo %js_files%
C:\path\to\jsminifier.exe --inputfiles %js_files%

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Windows command line: How to append a variable in a loop?

Low Risk

Try changing it to this: Note the change of to – by using the exclamation points in place of percent signs, you're instructing the shell to expand the environment variable dynamically during execution.

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment