0

I have a script that I've put together that should copy the list of files to a variable but the only thing I receive is the last file. In other words, when I echo the variable in my for loop, I see 20 or so files but only the last one gets copied to my variable. How can I get them all to copy correctly?

I am using Windows 7.

@echo off
setlocal enabledelayedexpansion enableextensions

for /r %%x in (*) do (
    echo %%x
    SET PATH_VALUE=%%x;%PATH_VALUE%
)

1 Answer 1

1

One way is to use delayed expansion. You've enabled it – half the job done. Now you only want to use it. Replace the %s around PATH_VALUE with !s and you are done:

@echo off
setlocal enabledelayedexpansion enableextensions

for /r %%x in (*) do (
    echo %%x
    SET PATH_VALUE=%%x;!PATH_VALUE!
)
Sign up to request clarification or add additional context in comments.

1 Comment

Wow! I tried something similar to that earlier and it didn't work but that did! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.