Solved

file modified times

Posted on 2002-05-12
2
219 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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

6 Experts available now in Live!

Get 1:1 Help Now