Reputation: 21
So I want to Echo %%a into another txt file, but seems nothing works to me. Here's the code :
for /f "delims=" %%a in (
'dir "*.txt" /b /s /a-d'
) do Echo for /f "delims=" %%a in ^( >> "%%a"
Simple : output file looks like:
"for /f "delims=" C:\Documents and Settings\xxxxx\Desktop\alpha\lol.txt in ( " .
I just need not a full path but "%%a". Bat file.
Upvotes: 1
Views: 59
Reputation: 82337
As you saw, it's not directly possible to escape the %%a
expression in a loop.
But like Magoo mention, it can be solved with changing the loop parameter.
You could also use the parser to create the %%a
output.
setlocal EnableDelayedExpansion
set "static=for /f "delims=" %%%%a in ("
for /f "delims=" %%a in ( 'dir "*.txt" /b /s /a-d') do (
echo !static! >> "%%a"
)
The content of the variable static
will be expanded, but the inner %%a
will not expanded later.
Upvotes: 0
Reputation: 80138
You want the literal %%a
?
Try %%%%a
Second suggestion:
Try %%%%^a
Third - change the metavariable (loop-control variable) to %%b
for /f "delims=" %%b in (
'dir "*.txt" /b /s /a-d'
) do Echo for /f "delims=" %%%%a in ^( >> "%%b"
Upvotes: 1
Reputation: 7095
Try this:
for /f "delims=" %%a in ('dir "*.txt" /b /s /a-d' ) do Echo %%a >> output.txt
Upvotes: 0