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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling the most recent file by file name?

Status
Not open for further replies.

FinnMan

Technical User
Feb 20, 2001
75
US
I'm attempting to do some scripting but not too sure how to go about it via regex.

I have a directory containing several files labeled in the following format:

bb010502.html
bb011002.html
bb011402.html

As you can probably tell, the file name is bb followed by the date (not necessarily the date of creation).

How would I regex grabbing the filename of the latest file in the directory based on the filename?

Thx a bunch,
FM
 
Ok...I've gotten a bit closer to my answer.

I need to do a string comparison (I think) of all the values in the array and then list the greatest value.

Does this sound right? If so any examples you could share would be helpful.

Thx,
FM
 
This can be done with sort.

@Sorted = sort(@FileList);
$LastFile = $Sorted[$#Sorted];
 
# see "perldoc -f sort"

# sort numerically
@sorted = sort {$a <=> $b} @data;

# sort numerically and return greatest:
$greatest = (sort {$a <=> $b} @data)[-1];
# or
$greatest = (sort {$b <=> $a} @data)[0];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top