Find newest file in all subdirectories

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Find newest file in all subdirectories

#16 Post by penpen » 28 Dec 2013 17:52

pditty8811 wrote:Perhaps I'm implementing it wrong. I just copy and paste it in a .bat file and then launch it.
This is how it is intended.

pditty8811 wrote: It just opens and closes. Where do I put the pause command?
It sounds, like you started it by double clicking the bat file, or similar.
You might add a pause between the "cscript ..." and the "goto :eof",
although it is meant to be used from cmd.exe shell or from another batch,
so you can add the optional unnamed parameter specifying a different path:

Code: Select all

@if (true==false) /*
@echo off

cscript //nologo //e:JScript "%~f0" %*
pause
goto :eof
*/
@end
...

penpen

pditty8811
Posts: 184
Joined: 21 Feb 2013 15:54

Re: Find newest file in all subdirectories

#17 Post by pditty8811 » 28 Dec 2013 19:38

penpen wrote:
pditty8811 wrote:Perhaps I'm implementing it wrong. I just copy and paste it in a .bat file and then launch it.
This is how it is intended.

pditty8811 wrote: It just opens and closes. Where do I put the pause command?
It sounds, like you started it by double clicking the bat file, or similar.
You might add a pause between the "cscript ..." and the "goto :eof",
although it is meant to be used from cmd.exe shell or from another batch,
so you can add the optional unnamed parameter specifying a different path:

Code: Select all

@if (true==false) /*
@echo off

cscript //nologo //e:JScript "%~f0" %*
pause
goto :eof
*/
@end
...

penpen


Ok great, I got it to work.

What if I was to use the code directly in my batch files instead of calling it with a param. Where then would I put the directory to search?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Find newest file in all subdirectories

#18 Post by foxidrive » 28 Dec 2013 20:44

It's a nice tool penpen.

I tested it in several folders and it worked well.

Edited: tested the newest code.



For what it's worth, the 623 was the file size below.

Code: Select all

12/01/2011  09:50               623 Donation to Premier’s Disaster Relief Appeal.txt

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Find newest file in all subdirectories

#19 Post by penpen » 29 Dec 2013 07:18

pditty8811 wrote:What if I was to use the code directly in my batch files instead of calling it with a param. Where then would I put the directory to search?
Assumed that the script file has the name "getNewest.bat" and you want to search the directory "P:\ath" and all its subfolders you just have to use:

Code: Select all

cscript //nologo //e:JScript "getNewest.bat" "P:\ath"
or if you have inserted the jscript code in your batch, you may call it:

Code: Select all

cscript //nologo //e:JScript "%~f0" "P:\ath"


penpen

Post Reply