How to call the oldest batch file from another batch file.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
emky
Posts: 3
Joined: 08 Jul 2012 13:43

How to call the oldest batch file from another batch file.

#1 Post by emky » 08 Jul 2012 13:52

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

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: How to call the oldest batch file from another batch fil

#2 Post by Fawers » 08 Jul 2012 14:32

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.

emky
Posts: 3
Joined: 08 Jul 2012 13:43

Re: How to call the oldest batch file from another batch fil

#3 Post by emky » 08 Jul 2012 17:46

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

emky
Posts: 3
Joined: 08 Jul 2012 13:43

Re: How to call the oldest batch file from another batch fil

#4 Post by emky » 08 Jul 2012 18:02

Thank you, I figure that one out (the easy part). I added %oldBat% this to run it.

thanks again for saving my day!
Alex

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: How to call the oldest batch file from another batch fil

#5 Post by Fawers » 08 Jul 2012 19:23

Alternatively, you can use CALL or START [/WAIT]. These make your code more readable. ;)

Post Reply