Gunnar Hjalmarsson wrote:F H wrote:I have a directory where log files are saved in on a daily basis by a VB program. and what I need is a way to get the last file stored into that directory. The last modified file in that directory should do it.
perldoc -f stat
What I am looking for is how "code wise" find the last modified file in a directory within a script. here us my script
<irrelevant part of the script snipped>
my $my_file_txt = 'P:\\Program Files\\Prog_Dir\\myfile062804.txt'; ### this is where I get stuck. the file in this dir changes everyday and I ###need to grab the last modified one and email it.
Why would the context make a difference?
I pointed you to the docs for a Perl function that lets you grab the last modified time for a file, and consequently should be relevant for your problem. Did you read that documentation?
There are admittedly other things involved, but you haven't let us know what it is that you find difficult. What have you tried so far? Or are you just asking that someone fixes the code for you for free? You shouldn't do that, you know.
Anyway, I'm in a good mood, so here is a suggestion:
my $my_file_txt = lastfile('P:/Program\ Files/Prog_Dir');
sub lastfile { my ($dir, %files) = shift; @files{ grep -f, <$dir/*> } = (); $files{$_} = (stat $_)[9] for keys %files; ( sort { $files{$b} <=> $files{$a} } keys %files )[0] }
But please don't use it until you have taken the time to get an understanding of what it does.
-- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>