Solved

Time-Stamp & Filename Hash

Posted on 1998-11-24
2
669 Views
Last Modified: 2008-02-20
Hi,

Want to create an associative array of filename and timestamp from a listing of a directory on a unix box.

Any pointers?

Thanks,

Andreas
0
Comment
Question by:context
2 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 100 total points
ID: 1206555
perldoc File::Listing starts with ....

NAME
    parse_dir - parse directory listing

SYNOPSIS
     use File::Listing;
     for (parse_dir(`ls -l`)) {
         ($name, $type, $size, $mtime, $mode) = @$_;
         next if $type ne 'f'; # plain file
         #...
     }

     # directory listing can also be read from a file
     open(LISTING, "zcat ls-lR.gz|");
     $dir = parse_dir(\*LISTING, '+0000');

DESCRIPTION
    The parse_dir() routine can be used to parse directory listings.
    Currently it only understand Unix `'ls -l'' and `'ls -lR''



So,

use File::Listing;

for (parse_dir(`ls -l`)) {
    ($name, $type, $size, $mtime, $mode) = @$_;
    next if $type ne 'f'; # plain file
    $Files{$name} = $mtime;
}


0
 
LVL 84

Expert Comment

by:ozo
ID: 1206556
opendir(DIR,'.');
%Files=map{$_,(stat $_)[9]}readdir(DIR);
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
binary to char / hexadecimal 5 113
syslog unix file 20 73
Help with a Script that will rename a file when it's not longer being written to 5 72
Extract data from span tag 1 92
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

773 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