Re: Problem with STAT under Windows



anders wrote:
I tryed some testkod below, i like Perl to give med TIME for every
file,
But all variable just get blank, (i got filename).

You need to either alter the current directory using chdir(), or pass the full path to stat().

You may want to try this code:

use strict;
use warnings;
use Data::Dumper;

my $dir_to_open = 'f:/backupsv';
my $files = readFileList($dir_to_open);
print Dumper $files;

sub readFileList {
my $dir = shift;
opendir my $dh, $dir or die $!;
my @files = grep /\.txt/i, readdir $dh;
my %result;
foreach my $file ( @files ) {
@{ $result{$file} }{ qw/size atime mtime ctime/ } =
( stat "$dir/$file" )[7..10];
}
return \%result;
}

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
.



Relevant Pages

  • Re: If..Then statement
    ... >> Trends" ... Workbooks.Open Filename:= _ ...
    (microsoft.public.excel.misc)
  • Re: block of code doesnt get executed
    ... Check to see if chdir() succeeded: ... $filename has not been used until now, ... A carat in a regex means the beginning of a string. ... [snip rest of code] ...
    (comp.lang.perl.misc)
  • Re: If..Then statement
    ... Workbooks.Open Filename:= _ ...
    (microsoft.public.excel.misc)
  • Re: Email Attachment Problem
    ... I created another filename string, so I can use it in the subject ... ChDir and set the default to the zipped files directory. ... >> Dim strDate As String, DefPath As String, strbody As String ...
    (microsoft.public.excel.programming)
  • Re: Prompt for filename in excel macro VBA
    ... I'm setting up a basic macro to copy data from one spreadsheet to the ... prompt to enter the filename? ... ' UpdateCurrentWeek Macro ...
    (microsoft.public.excel.programming)