I am trying to call the oldest batch file from another batch file.
Here is what I am trying to do:
I have a batch file called C:/app/caller.bat (File Name Static). I want caller.bat file to call the oldest batch file in C/app/outbound (There could be 3-4 batch files in the outbound folder).
I am looking for any directions or suggestion.
thanks
Alex
How to call the oldest batch file from another batch file.
Moderator: DosItHelp
Re: How to call the oldest batch file from another batch fil
Maybe this piece of code will help you.
(untested)
Insert these lines in your caller.bat and tell us if it does what you want it to.
Code: Select all
pushd "C/app/outbound"
for /f "delims=" %%a in ('dir /b /o-d *.bat') do set "oldBat=%%~fa"
popd
echo oldBat == %oldBat%
pause
(untested)
Insert these lines in your caller.bat and tell us if it does what you want it to.
Re: How to call the oldest batch file from another batch fil
This is exactley what I wanted to do. It displays the oldest file for me. One more thing I left out on my initial request is that, after I found the oldest batch file, I want to run it.
thank you so much!
Alex
thank you so much!
Alex
Re: How to call the oldest batch file from another batch fil
Thank you, I figure that one out (the easy part). I added %oldBat% this to run it.
thanks again for saving my day!
Alex
thanks again for saving my day!
Alex
Re: How to call the oldest batch file from another batch fil
Alternatively, you can use CALL or START [/WAIT]. These make your code more readable.