Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Finding the newest directory

Reply
Thread Tools

Finding the newest directory

 
 
sc0ri0n
Guest
Posts: n/a
 
      05-13-2004
Hi,

If I have a bunch of directories and files (sun solaris). Is there a way to
find the newest directory (last one created not modified)?

TIA


 
Reply With Quote
 
 
 
 
Sam Holden
Guest
Posts: n/a
 
      05-13-2004
On Wed, 12 May 2004 22:52:42 -0400, sc0ri0n <(E-Mail Removed)> wrote:
> Hi,
>
> If I have a bunch of directories and files (sun solaris). Is there a way to
> find the newest directory (last one created not modified)?


No (unless you are using a funky non-standard file system).

Creation time is not tracked by the filesystem.

You have (most recent) access time, modification time, and
file status time. File status time (ctime) is as close as
you'll get, but it is set by other operations that change
the file status (such as chmod(), link(), unlink(), etc.)

stat gives you access to the ctime.

perldoc -f stat

--
Sam Holden
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      05-13-2004

Quoth http://www.velocityreviews.com/forums/(E-Mail Removed):
> On Wed, 12 May 2004 22:52:42 -0400, sc0ri0n <(E-Mail Removed)> wrote:
> > Hi,
> >
> > If I have a bunch of directories and files (sun solaris). Is there a way to
> > find the newest directory (last one created not modified)?

>
> No (unless you are using a funky non-standard file system).
>
> Creation time is not tracked by the filesystem.
>
> You have (most recent) access time, modification time, and
> file status time. File status time (ctime) is as close as
> you'll get, but it is set by other operations that change
> the file status (such as chmod(), link(), unlink(), etc.)
>
> stat gives you access to the ctime.


....and you'll likely want File::Find to do the searching.

OTOH, you could probably do this more easily with find(1).

Ben

--
For the last month, a large number of PSNs in the Arpa[Inter-]net have been
reporting symptoms of congestion ... These reports have been accompanied by an
increasing number of user complaints ... As of June,... the Arpanet contained
47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] * (E-Mail Removed)
 
Reply With Quote
 
sc0ri0n
Guest
Posts: n/a
 
      05-13-2004
Sam,

I am not interested in files at all. There is a process that creates
directories. What I need to do is to detect the one created last and move
all of its content.

Also, I am new to unix so I am not sure if there are other statistics for
directories like last modified or last accessed as in files?

Thanks,
Pete


"Sam Holden" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed). ..
> On Wed, 12 May 2004 22:52:42 -0400, sc0ri0n <(E-Mail Removed)> wrote:
> > Hi,
> >
> > If I have a bunch of directories and files (sun solaris). Is there a way

to
> > find the newest directory (last one created not modified)?

>
> No (unless you are using a funky non-standard file system).
>
> Creation time is not tracked by the filesystem.
>
> You have (most recent) access time, modification time, and
> file status time. File status time (ctime) is as close as
> you'll get, but it is set by other operations that change
> the file status (such as chmod(), link(), unlink(), etc.)
>
> stat gives you access to the ctime.
>
> perldoc -f stat
>
> --
> Sam Holden



 
Reply With Quote
 
Sam Holden
Guest
Posts: n/a
 
      05-13-2004
On Wed, 12 May 2004 23:12:08 -0400, sc0ri0n <(E-Mail Removed)> wrote:
> Sam,
>
> I am not interested in files at all. There is a process that creates
> directories. What I need to do is to detect the one created last and move
> all of its content.


Directories are just files, just like block devices are just files.

>
> Also, I am new to unix so I am not sure if there are other statistics for
> directories like last modified or last accessed as in files?


Directories are just files. They have all the same metadata.

[snip full quote, sigs and all]

Please don't do that, put your reply after the text you
are replying to - trim irrelevant text if it's too long.

--
Sam Holden
 
Reply With Quote
 
Sam Holden
Guest
Posts: n/a
 
      05-13-2004
On Thu, 13 May 2004 03:09:51 +0000 (UTC),
Ben Morrow <(E-Mail Removed)> wrote:
>
> Quoth (E-Mail Removed):
>> On Wed, 12 May 2004 22:52:42 -0400, sc0ri0n <(E-Mail Removed)> wrote:
>> > Hi,
>> >
>> > If I have a bunch of directories and files (sun solaris). Is there a way to
>> > find the newest directory (last one created not modified)?

>>
>> No (unless you are using a funky non-standard file system).
>>
>> Creation time is not tracked by the filesystem.
>>
>> You have (most recent) access time, modification time, and
>> file status time. File status time (ctime) is as close as
>> you'll get, but it is set by other operations that change
>> the file status (such as chmod(), link(), unlink(), etc.)
>>
>> stat gives you access to the ctime.

>
> ...and you'll likely want File::Find to do the searching.
>
> OTOH, you could probably do this more easily with find(1).


I thought about find(1), but it finds all the files that match
the expression you give it. I don't know how to tell it to
output just the newest, or the biggest, of the anythingest for
that matter.

My first guess would be something like:

my $the_winner;
{
my $the_winners_ctime;
for (get_the_directory_paths()) {
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat;
if (!defined $the_winner or $the_winners_ctime < $ctime) {
$the_winner = $_;
$the_winners_ctime = $ctime;
}
}
}
print "$the_winner\n";

But ctime gets set by write(2) so the whole thing is pointless...

--
Sam Holden

 
Reply With Quote
 
Joe Smith
Guest
Posts: n/a
 
      05-13-2004
sc0ri0n wrote:

> Sam,
>
> I am not interested in files at all. There is a process that creates
> directories. What I need to do is to detect the one created last and move
> all of its content.
>
> Also, I am new to unix so I am not sure if there are other statistics for
> directories like last modified or last accessed as in files?


foreach my $entry (glob '*') {
print +(-d $entry ? 'Directory' : 'File'), " $entry is ", -s _, " bytes\n";
printf " Modified %6.2f days ago\n", -M _;
printf " Accessed %6.2f days ago\n", -A _;
printf " Changed %6.2f days ago\n", -C _;
}

-Joe
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Show newest file in directory? Mmcolli00 Mom Ruby 6 12-19-2008 08:15 AM
finding newest file in a directory and removing the rest Stu Perl Misc 10 10-13-2008 10:47 PM
reading a directory, first files the newest ones jordilin Perl Misc 17 10-29-2007 11:07 PM
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
Newest URLs on top of address bar A Firefox 1 08-30-2005 01:42 PM



Advertisments