In your case you would add a
cd /d D:\Testdata
before the for command to change to the right dir.
Also not if you try this from a cmd.exe prompt rather than a batch file you have to replace the two %%a with just %a instead. What the for command is doing is taking the output of the dir command line at a time, and assigning the whole output line (tokens=*) to the variable shown (%%a) and running whatever you put after the do for each. This can be more than one command if needed with:
for ..... do (command1
command2
command3
)
etc
Steve
Main Topics
Browse All Topics





by: dragon-itPosted on 2009-11-16 at 08:43:12ID: 25831600
There is a "FOR" command which does exactly that. You can do it a number of ways, two I will show here, either using for to do a directory listing itself or using a dir command with the /b switch to make a bare list of the files you want.
@echo off
for /r %%a in (*.txt) do yourexe %%a
or
@echo off
for /f "tokens=*" %%a in ('dir /b /a-d *.txt') do yourexe %%a
for /? has lots of info. on these syntax (though takes a bit of hard reading!)
hth, ask if you need more.
Steve