hi,
I want to get the latest file in a Directory by providing the starting characters of a file name. With this code, I am able to get the file based on the name.But it will start searching files in dirctory based on file names(will search for the files based on file name sorted in ascending order).So if timestamp is there in 2 macthing file, i will get the earlier file as filename is smaller for that. i need to get the file serach to be done based on the updated timestamp of the files in the directoy.Please help.
#!/usr/bin/perl
use Getopt::Std;
use File::Find;
getopts('i:');
$file_serch= $opt_i;
$dir = "/MYDIR/";
find(\&edits, $dir);
sub edits()
{
$pos = rindex $File::Find::name,'/';
$file_name = substr($File::Find::name,$pos+1,length($File::Find::n
+ame));
$in_file = $file_name if ($file_name=~ m/^$file_serch/);
exit if $in_file ne "";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.