Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find most recent file created in a folder

Status
Not open for further replies.

LuckyDuck528

Programmer
Dec 21, 2004
65
US
Is there a simple way to find the most recent file created/modified in a specific folder.

I was wondering so that I didn't have to go through the whole folder and compare each date and put the first date in an array and repalce the array value if the next file had a mroe recent date... that just seems so long and drawn out...

Any other suggestions?

Thank you!
 
A starting point:
strFolder = "C:\Temp"
WScript.Echo CreateObject("WScript.Shell").Exec("cmd /C dir """ & strFolder & """ /A-D/O-D/TW/B").StdOut.ReadLine

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Wow thanks! That works beautifully, but is there a way to make the output equal a variable name?
 
That is to say... I'd like it to equal a variable name without having to write it to a .txt file and then open the .txt file and read the name...

Thanks!
 
Replace this:
WScript.Echo
By something like this:
myVar =

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top