Solved

file modified times

Posted on 2002-05-12
2
251 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
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 …
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…

829 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