If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > How to find the last modified directory?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-16-08, 22:36
lilly07 lilly07 is offline
Registered User
 
Join Date: Jul 2008
Posts: 1
How to find the last modified directory?

I could find the last modified file in a directory as below.

Code:
#!/usr/bin/perl

my $directory = '/home/userrig/testing/';
opendir(DIR2, $directory) or die "Can't open $directory: $!";
@files = grep {/\.txt$/i} readdir(DIR2); #get txt files only
closedir(DIR2);
@sorted = sort {-M "$directory$a" <=> -M "$directory$b"} @files; #sort them by modification date most recent to least recent
print "The most recent modified file is: $sorted[0]";
How do I modify so that I can get the last modified directory under /home/userrig/testing/', the directories starting with test...

Thanks.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On