For - Change Variable

Microsoft Windows xp professional w/serv...
May 13, 2010 at 11:30:33
Specs: Windows XP
Hi All,

I have been trying to understand what happens
inside this code but without success. Please,
check below:

1. I have the following files inside a directory:
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
D:\Files\in
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Test_1.txt
Test_2.txt
Test_3.txt
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

And I have the following code:
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
SET MYPATH="D:\Files\in\*.txt"
FOR %%F IN (%MYPATH%) DO (
SET MYFILE=%%F
SET MYFILEFS=%MYFILE:\=/%
ECHO "F: [%%F] - MYFS: [%MYFILEFS%]."
)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

The output is:
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"F: [D:\Files\in\Test_1.txt] - MYFS: []."
"F: [D:\Files\in\Test_2.txt] - MYFS: []."
"F: [D:\Files\in\Test_3.txt] - MYFS: []."
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Question:
Why "MYFS: [%MYFILEFS%]" is not showing
and "F: [%%F]" shows? Is there something
wrong with my code?

Also, is there a way to change backslashes to
front slashes on %%F?

Thanks for your help!

Regards.


See More: For - Change Variable

Report •

#1
May 13, 2010 at 12:02:20
required reading:
set /?
for replacement, "page" 2: set !myfs:/=\!
for delayed expansion, start from top of "page" 3.

Report •

#2
May 13, 2010 at 13:11:51
Hi nbrane,

Thanks for the update! After posting here, I found about
delayed expansion.

If someone else have such problem, just check:
http://stackoverflow.com/questions/...
enabledelayedexpansion-query

Again, thanks for your attention!

Regads!


Report •
Related Solutions


Ask Question