So, I was playing around splitting strings and I came across this situation:
for /f "tokens=1" %%c in ("A B C") do (
set s=%%c
echo s: %s%
)
pause
I expected it to print:
s: A
But it actually prints:
s:
Why?
What I'm trying to do is: I have some folders whose names have a default placement (id name, e: 123 ABC), and inside each folder I have a file I need to copy but the file name is different in each one so I need to get the name of the folder without the id, what I thought was supposed to do that was this:
cd C:\MyFolders
pause
for /d %%a in (*) do (
set name=%%a
for %%b in ("%%a\*.txt") do (
for /f "tokens=1" %%c in ("%%a") do (
set id=%%c
set name_without_id=%name%:%id% =
echo new file name: %name_without_id%
)
)
)
pause
I thought it could be a bug in my code, so I did the first one, really simple, but yet I didn't get what I was expecting.