CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Getting file date stamp

 



jacqui
Novice

Apr 18, 2000, 11:36 AM

Post #1 of 8 (1077 views)
Getting file date stamp Can't Post

Hi,

Can anybody please tell me how I can get and display the date a file was created.

Thanks

Jac
xxx


Cure
User

Apr 18, 2000, 1:54 PM

Post #2 of 8 (1077 views)
Re: Getting file date stamp [In reply to] Can't Post

Hi

Unix filesystems don't store the creation date.


Cure


Jasmine
Administrator / Moderator

Apr 18, 2000, 3:51 PM

Post #3 of 8 (1078 views)
Re: Getting file date stamp [In reply to] Can't Post

While you may not be able to grab the exact date (Tues Apr 18 2000) of the file, you can get the information that will help you generate the creation date in addition to the last accessed and last modified date.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


$file = "filetotest.htm";

print "File Created " . (-C $file) . " days ago<BR>";

print "Last Accessed " . (-A $file) . " days ago<BR>";

print "Last Modified " . (-M $file) . " days ago<BR>";
</pre><HR></BLOCKQUOTE>

The results are expressed in "days ago", which is relative to the date/time that the program is executed.


Cure
User

Apr 18, 2000, 6:49 PM

Post #4 of 8 (1077 views)
Re: Getting file date stamp [In reply to] Can't Post

Hi


To find out things about a file use the stat() function. Type "perldoc -f stat" at your command prompt.


Cure


Cure
User

Apr 18, 2000, 7:14 PM

Post #5 of 8 (1077 views)
Re: Getting file date stamp [In reply to] Can't Post

Hi


Use the File::stat module and that will take care of your needs.

This module's default exports override the core stat()
and lstat() functions, replacing them with versions that return
"File::stat" objects. This object has methods that
return the similarly named structure field name from the
stat(2) function; namely,
dev,
ino,
mode,
nlink,
uid,
gid,
rdev,
size,
atime,
mtime,
ctime,
blksize,
and
blocks.


To find out when a file was created, just do this->

#!/usr/bin/perl
use File::stat;
$file = "filetotest.htm";
$sb=stat($file);
print scalar localtime $sb->mtime;


Cure



[This message has been edited by Cure (edited 04-18-2000).]


jacqui
Novice

Apr 18, 2000, 10:10 PM

Post #6 of 8 (1077 views)
Re: Getting file date stamp [In reply to] Can't Post

Jasmine, Cure - Thanks for your help.

I went for the -M one in the end :-)

Jac
xxx


Rivotti
User

Apr 19, 2000, 2:31 AM

Post #7 of 8 (1077 views)
Re: Getting file date stamp [In reply to] Can't Post

Hi:

Is it possible to set a time life to a file, for example 1 year?

Rivotti


Cure
User

Apr 19, 2000, 6:27 PM

Post #8 of 8 (1077 views)
Re: Getting file date stamp [In reply to] Can't Post

Hi

to delete a file a year from now

my $dir = '/absolute/path/to/directory';

chdir $dir or die "Couldn't chdir to '$dir'. $!\n";

defined (unlink grep -f && -M _ > 365 => readdir $dir) or
die "Couldn't unlink from '$dir'. $!\n";


Cure

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives