0

I saw a couple similar questions but could quite cobble together what I want. This was close because it gives me the name of the most recent batch file:

for /f "delims=" %%x in ('dir /od /b c:\maps\*.bat') do set recent=%%x
echo %recent%

But the batch file that contains this is in, say, c:\start, so I need to get back a full pathname, not just the filename. I can then use "call" to run the batch file.

(I'm doing this on xp, incidently.)

1
  • You must know the path from when you ran the dir command?? Commented May 10, 2012 at 17:46

3 Answers 3

1

if you use

 for /f "delims=" %%x in ('dir /od /b c:\maps\*.bat') do set recent=%%x

you positively know that the full path of the file will be c:\maps\%%x


Alternatively, if you use dir /s instead, it will iterate over all the existing subdirectories

for /f "delims=" %%x in ('dir /od /b /s c:\maps\*.bat') do set recent=%%x

but with the interesting side effect of returning the full path, that will be %%x.

Sign up to request clarification or add additional context in comments.

1 Comment

Great! I think I'll use the second method for my script.
0

try to use :

for /f "delims=" %%x in ('dir /od /b /s c:\maps\*.bat') do set recent=%%x
echo %recent%

Comments

0

This worked better for me than /s, which had poor performance:

for /f "delims=" %%x in ('dir /od /b c:\maps\*.bat') do set recent=%%~fx

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.