473,385 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to open a directory and print out dates of all the files?

Need to write a perl script to open a dir and print out the date of all files last modified. This is what I have but keep getting error...

use File::stat;
open "D,"$ARGV[0]") or die "Can't open dir\n";

while(defined($file = readdir D))
{
next if ! -T $file;
$last_mod = (stat($file))[9] or die "Can't stat\n";
print"$file:\t$last_mod\n";
}

Keep getting "Can't stat"!!! What did I do wrong??? Any help is appreciated....
Nov 8 '10 #1
4 1859
Oralloy
988 Expert 512MB
new bie,

If you read the File::stat module documentation, you'll see that there are problems with the -T operator. I don't know if this is what is affecting you or not.

Are you, perhaps, running on a Windows box, rather than a Linux box?
Nov 9 '10 #2
Oralloy
988 Expert 512MB
Curse, what am I saying. Even if -T fails, you're still failing to stat(), aren't you?

Can you add the file name that's causing problems?
Expand|Select|Wrap|Line Numbers
  1. use File::stat;
  2. open "D,"$ARGV[0]") or die "Can't open dir\n";
  3.  
  4. while(defined($file = readdir D))
  5. {
  6.   next if ! -T $file;
  7.   $last_mod = (stat($file))[9] or die "Can't stat '$file'\n";
  8.   print"$file:\t$last_mod\n";
  9. }
BTW, here is the man page from perl.org.
Nov 9 '10 #3
RonB
589 Expert Mod 512MB
The open function is used to open a file, not a directory. You need to use opendir.

perldoc -f open
http://perldoc.perl.org/functions/open.html

perldoc -f opendir
http://perldoc.perl.org/functions/opendir.html
Nov 10 '10 #4
Oralloy
988 Expert 512MB
@RonB - good catch, man! I think you just solved all his problems.
Nov 10 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: msn | last post by:
I have plane to develop MSN messenger clone. And I wanna develop it using the latest MSN messenger API but I can't find any information about the latest MSN messenger API. Does anyone know about...
1
by: M.N.A.Smadi | last post by:
hi guys; sorry for sending a perl question here, but python guy "HAD TO" look at perl code; how can i split a string that contains white spaces and '_' any clue? thanks
7
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - I have a question that is not answered in here or in any of the resources mentioned here but I'm sure it has been...
2
by: TARUN | last post by:
I have a question about declaring the Global.ascx: In VS.NET I create a Solution, and there are 4 projects under it. They are put under 4 folders, but web pages would be called across the 4...
3
by: dolphin | last post by:
Is there someone have written some programs about RSA-1024.What about Montgomery?What it is?What is the result of it?sorry for my poor english.
17
by: manuthomas23 | last post by:
I have a question: What will be the value of j in the following code? and why is it so? int i; for( i = 0; i < 1; i++ ) { switch( i ) { case 0: i += 5;
9
by: lorlarz | last post by:
I still have a question regarding the following code, in a commonly used routine. First, Here's the code in question: Function.prototype.bind = function(){ var fn = this, args =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.