Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

file modified times

Posted on 2002-05-12
2
Medium Priority
?
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
japhyRPI earned 800 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
Six Sigma Control Plans

609 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