Solved

extracting a date in a file

Posted on 2000-05-01
4
168 Views
Last Modified: 2010-03-05
how would you go about extracting the date of and file size from files?
0
Comment
Question by:kaleid
  • 2
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 100 total points
ID: 2767104
you can use the stat function of PERL to do get the size of the file.

however you cant directly get the date of the file. you can only get the Last access time, Last modification time & File creation time in seconds.

This function returns a 13-element list giving the statistics for a file, either the file opened via FILEHANDLE, or named by EXPR.
It's typically used as follows:

($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,    $atime,$mtime,$ctime,$blksize,$blocks) = stat $filename;

here is a sample script that shows you how.

===file_sz.pl
#!/usr/local/bin/perl

$file="/tmp/test.pl";

($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
    $atime,$mtime,$ctime,$blksize,$blocks)
            = stat $file;

print "file size is $size\n";

##Last access time, Last modification time & File creation time in seconds.
print "$atime $mtime ctime\n";
0
 

Author Comment

by:kaleid
ID: 2775043
Adjusted points from 50 to 100
0
 

Author Comment

by:kaleid
ID: 2775044
Thank you maneshr, much appreciated.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2775062
anytime... most welcome :-)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question