Find Latest .xls File in a Directory

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
dazedandconfused2
Newbie
Posts: 13
Joined: Tue Aug 29, 2006 1:50 am

Find Latest .xls File in a Directory

Post by dazedandconfused2 » Wed Aug 13, 2008 4:21 am

Greetings

I need to find the latest .xls file in a directory that has multiple types of
files in it.

I can get the latest file from the directory but if I try and apply a
wildcard expression to the file request I get errors.

I am using code very similar to this

http://www.mjtnet.com/forum/viewtopic.php?p=8011

How do I script for a specific file extension.

Thanks

Greg

User avatar
JRL
Automation Wizard
Posts: 3505
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Aug 13, 2008 4:36 am

Someone will, I'm sure, jump in with a VBScript solution. But I like DOS. The variable "file_1" will contain the newest .XLS file. The variable "file_%file_count%" will contain the oldest.

Code: Select all

Let>file1=drive:\path\

Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run>cmd /c dir "%file1%*.xls" /o-d /b >%temp_dir%~fileList.txt
Readfile>%temp_dir%~fileList.txt,filedata
Separate>filedata,%CRLF%,file
Sub>file_count,1

MDL>The newest file is :%file_1% 

dazedandconfused2
Newbie
Posts: 13
Joined: Tue Aug 29, 2006 1:50 am

Post by dazedandconfused2 » Wed Aug 13, 2008 8:48 pm

I would like a VB solution but I may just go with yours in the short term.

Thanks

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts