I'm trying to create a batch file that runs through several folders in a for /d listing and then echoes the oldest file in the folder. Ultimately, this will be used to move files to another folder. The problem I have is I can't get the for /f to escape without ending the entire command.
@echo off
setlocal enableextensions disabledelayedexpansion
set basefolder=M:\somefolder\*
for /D %%D in (%basefolder%) do (
FOR /F %%I IN ('DIR %%D\* /B /O:-D') DO echo "%%I" & goto moved
:moved
)
This get me ") was unexpected"
@echo off
setlocal enableextensions disabledelayedexpansion
set basefolder=M:\somefolder\*
for /D %%D in (%basefolder%) do (
FOR /F %%I IN ('DIR %%D\* /B /O:-D') DO echo "%%I" & exit /b
)
This, of course, exits the command at the first folder that processed.
Can someone suggest something that might actually work?