Re: help with getting file stats
Eric Amick wrote: On Thu, 21 Jul 2005 12:05:08 -0700, you wrote: loris reply: yes I did try stat ("$dir/$file") it would not work , and I tried many variation here is what I finally got to work: print "Opening $dir \n"; opendir DH, $dir or die "Can't open the current dir $!\n"; while(my $file = readdir(DH)){ if(-d "$dir/$file"){ print "\n Dir: $file \n"; my $pic_year = substr($file,0,4); my $pic_month = substr($file,4,2); print "Year: $pic_year,Month: $pic_month\n"; $dir_ctr++; } elsif(-e "$dir/$file"){ print "\n File: $dir/$file "; #this wont work for me #my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,$atime, $mtime, $ctime, $blksize, $blocks) = stat("$dir/$file"); #print "Ctime:$ctime ,Mtime: $mtime\n"; my $now = ctime(); print "\n Nowtime: $now\n"; #this works my $file_moddate = ctime(stat("$dir/$file")->mtime); my $file_create_date = ctime(stat("$dir/$file")->ctime); Clearly you directly or indirectly use'd the File::stat module, which overrides the built-in stat() with an object-oriented version. If you really want to call the built-in version, try my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,$atime, $mtime, $ctime, $blksize, $blocks) = CORE::stat("$dir/$file"); Thanks Eric CORE::stat("$dir/$file"); you are correct if I dont use the File::stat module it will work so using CORE::stat("$dir/$file"); also works lori ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: help with getting file stats
On Thu, 21 Jul 2005 12:05:08 -0700, you wrote: >loris reply: >yes I did try stat ("$dir/$file") it would not work , and I tried many >variation >here is what I finally got to work: > >print "Opening $dir \n"; > > opendir DH, $dir or die "Can't open the current dir $!\n"; > while(my $file = readdir(DH)){ > >if(-d "$dir/$file"){ > print "\n Dir: $file \n"; > my $pic_year = substr($file,0,4); > my $pic_month = substr($file,4,2); > print "Year: $pic_year,Month: $pic_month\n"; > > $dir_ctr++; >} >elsif(-e "$dir/$file"){ > print "\n File: $dir/$file "; > #this wont work for me > #my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,$atime, >$mtime, $ctime, $blksize, $blocks) = stat("$dir/$file"); > #print "Ctime:$ctime ,Mtime: $mtime\n"; > my $now = ctime(); > print "\n Nowtime: $now\n"; > #this works > my $file_moddate = ctime(stat("$dir/$file")->mtime); > my $file_create_date = ctime(stat("$dir/$file")->ctime); Clearly you directly or indirectly use'd the File::stat module, which overrides the built-in stat() with an object-oriented version. If you really want to call the built-in version, try my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,$atime, $mtime, $ctime, $blksize, $blocks) = CORE::stat("$dir/$file"); -- Eric Amick Columbia, MD ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: help with getting file stats
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of lorid Sent: Wednesday, July 20, 2005 3:34 PM To: perl-win32-users Subject: help with getting file stats snip of loris code: ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ) = stat($file); print "\n $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,Mtime: $mtime,\n Ctime:$ctime,\n $blksize, $blocks\n"; $file_ctr++; } } Darrell Gammill wrote: Have you tried stat ("$dir/$file")? If you just stat ($file), $file would have to be the full path or a file in the current directory. Do you have a sample output you could share? -Dgg --- loris reply: yes I did try stat ("$dir/$file") it would not work , and I tried many variation here is what I finally got to work: print "Opening $dir \n"; opendir DH, $dir or die "Can't open the current dir $!\n"; while(my $file = readdir(DH)){ if(-d "$dir/$file"){ print "\n Dir: $file \n"; my $pic_year = substr($file,0,4); my $pic_month = substr($file,4,2); print "Year: $pic_year,Month: $pic_month\n"; $dir_ctr++; } elsif(-e "$dir/$file"){ print "\n File: $dir/$file "; #this wont work for me #my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,$atime, $mtime, $ctime, $blksize, $blocks) = stat("$dir/$file"); #print "Ctime:$ctime ,Mtime: $mtime\n"; my $now = ctime(); print "\n Nowtime: $now\n"; #this works my $file_moddate = ctime(stat("$dir/$file")->mtime); my $file_create_date = ctime(stat("$dir/$file")->ctime); print "\nfile create date: $file_create_date, file mod date: $file_moddate"; $file_ctr++; } } closedir DH; -- note : my verion of perl is v5.005_02 I will try the other code on another machine with newer perl v. and see if that helps... Thanks for all replies Lori ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: help with getting file stats
Have you tried stat ("$dir/$file")? If you just stat ($file), $file would have to be the full path or a file in the current directory. Do you have a sample output you could share? -Dgg -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of lorid Sent: Wednesday, July 20, 2005 3:34 PM To: perl-win32-users Subject: help with getting file stats I am trying to get the file stats I found this code in ch8 of perl cookbook ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ) = stat($filename) and read the man page for stat and perlfunc but cant seem to get a simple program to get the file stats after reading the man page for stat I thought my problem might be that I need to use fstat since the file may be open but that doesnt seem to work either any suggestions would be appreciated. my simple test program: #!/usr/local/bin/perl use File::stat; my $dir_ctr = 0; my $file_ctr = 0; my $dir = "/home/lorid/wrccpics"; print "Opening $dir \n"; opendir DH, $dir or die "Can't open the current dir $!\n"; while($file = readdir(DH)){ if(-d "$dir/$file"){ print "\n Dir: $file \n"; $dir_ctr++; } elsif(-e "$dir/$file"){ print "\nFile: $file \n"; ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ) = stat($file); print "\n $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,Mtime: $mtime,\n Ctime:$ctime,\n $blksize, $blocks\n"; $file_ctr++; } } print "\n"; print "number of directories: $dir_ctr"; print "\n"; print "number of files: $file_ctr"; print "\n"; ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: help with getting file stats
[EMAIL PROTECTED] wrote: > I am trying to get the file stats > I found this code in ch8 of perl cookbook > ( $dev, $ino, $mode, $nlink, > $uid, $gid, $rdev, $size, > $atime, $mtime, $ctime, > $blksize, $blocks ) = stat($filename) > > and read the man page for stat and perlfunc but cant seem to get a > simple program to get the file stats > after reading the man page for stat I thought my problem might be > that I need to use fstat since the file may be open > but that doesnt seem to work either > > any suggestions would be appreciated. > my simple test program: > > > #!/usr/local/bin/perl > > > use File::stat; > > > > my $dir_ctr = 0; > my $file_ctr = 0; > > > my $dir = "/home/lorid/wrccpics"; > > print "Opening $dir \n"; > > opendir DH, $dir or die "Can't open the current dir $!\n"; > while($file = readdir(DH)){ > > if(-d "$dir/$file"){ > print "\n Dir: $file \n"; > $dir_ctr++; > } > elsif(-e "$dir/$file"){ > print "\nFile: $file \n"; > ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, > $mtime, $ctime, $blksize, $blocks ) = stat($file); If you look at the -d and -e you will see that it is concatenating the dir and file. You are only giving it the file and it does not exist. You will need to either use the same setup of $dir/$file or you could do a chdir against the $dir and then the $file should work. Wags ;) > print "\n $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, > $atime,Mtime: $mtime,\n Ctime:$ctime,\n $blksize, $blocks\n"; > $file_ctr++; > } > > } > > print "\n"; > print "number of directories: $dir_ctr"; > print "\n"; > print "number of files: $file_ctr"; > > print "\n"; > ___ > Perl-Win32-Users mailing list > Perl-Win32-Users@listserv.ActiveState.com > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs *** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *** ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
help with getting file stats
I am trying to get the file stats I found this code in ch8 of perl cookbook ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ) = stat($filename) and read the man page for stat and perlfunc but cant seem to get a simple program to get the file stats after reading the man page for stat I thought my problem might be that I need to use fstat since the file may be open but that doesnt seem to work either any suggestions would be appreciated. my simple test program: #!/usr/local/bin/perl use File::stat; my $dir_ctr = 0; my $file_ctr = 0; my $dir = "/home/lorid/wrccpics"; print "Opening $dir \n"; opendir DH, $dir or die "Can't open the current dir $!\n"; while($file = readdir(DH)){ if(-d "$dir/$file"){ print "\n Dir: $file \n"; $dir_ctr++; } elsif(-e "$dir/$file"){ print "\nFile: $file \n"; ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks ) = stat($file); print "\n $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime,Mtime: $mtime,\n Ctime:$ctime,\n $blksize, $blocks\n"; $file_ctr++; } } print "\n"; print "number of directories: $dir_ctr"; print "\n"; print "number of files: $file_ctr"; print "\n"; ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs