Solved

file modified times

Posted on 2002-05-12
2
232 Views
Last Modified: 2010-03-05
Dear All,

I need to be able to output the last modified date of a file to a web page, but the perl below fails if there is any white space in the filename:

foreach $name (sort readdir(DIRHANDLE)) {
    $date_string = ctime(stat($name)->mtime);
    print $date_string
}

Does anyone know of an easy fix?  Is there some combination of quatation marks I have missed?

Thanks in advance,

Paul
0
Comment
Question by:paulmitch
2 Comments
 
LVL 1

Accepted Solution

by:
japhyRPI earned 200 total points
ID: 7004427
I don't have it fail the way you describe, but you're missing an important part.  readdir() only returns the NAME of the file, not the path TO it.  That means that

  opendir DIR, "/some/path";
  @files = readdir DIR;
  closedir DIR;

will only have "boo" and "gunk" in @files, not "/some/path/boo" and "/some/path/gunk".  That means that you must put those in manually:

  opendir DIR, $path or die "can't opendir $path: $!";
  for (sort readdir DIR) {
   print ctime(stat("$path/$_")->mtime);
  }
  closedir DIR;
0
 
LVL 1

Author Comment

by:paulmitch
ID: 7004451
Yeap, you got it....

Sorry for the false info - I moved the script into the real dir after running it from a test dir, so the path files were in the same dir as the script.  When I moved it, it lost the files.

Many thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delete query using perl dbi 3 95
syslog unix file 20 68
PHP pack() : What exactly is meant by signed char and unsigned char? 7 96
Perl Untar File 1 25
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now