So i’ve got a basic batch script that iterates over the directories and prints out each directory name:
for /R /D %%d in (.\*) do (
echo %%d
)
But I don’t like the single character variable d, I want it to be something more descriptive, like “directory”
for /R /D %%directory in (.*) do (
echo %%directory
)
Now I get the error “%directory was unexpected at this time”
Why does it accept a single letter variable, but not a multi letter variable?
That’s just the way the language works, and has been since the early days of DOS.
However, there’s nothing stopping you from assigning that variable to another one with a longer name – see
set.I wouldn’t concern myself for a short sample like this but it comes in handy when your loop body becomes more substantial.