Solved

file modified times

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

816 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

10 Experts available now in Live!

Get 1:1 Help Now