Page 1 of 1
How to call the oldest batch file from another batch file.
Posted: 08 Jul 2012 13:52
by emky
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
Re: How to call the oldest batch file from another batch fil
Posted: 08 Jul 2012 14:32
by Fawers
Maybe this piece of code will help you.
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
Posted: 08 Jul 2012 17:46
by emky
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
Re: How to call the oldest batch file from another batch fil
Posted: 08 Jul 2012 18:02
by emky
Thank you, I figure that one out (the easy part). I added %oldBat% this to run it.
thanks again for saving my day!
Alex
Re: How to call the oldest batch file from another batch fil
Posted: 08 Jul 2012 19:23
by Fawers
Alternatively, you can use CALL or START [/WAIT]. These make your code more readable.