Re: Problem with Code

From: Jan Eden (lists_at_janeden.org)
Date: 04/21/04


Date: Wed, 21 Apr 2004 14:21:40 +0200
To: Ryan Thomas <ryan@valetech.com>, Perl Lists <beginners@perl.org>

I do not see the error. But from your listing, I see you're on Windows. Could you try the following code (without any modifications):

---
#!/usr/bin/perl -w 
 use strict; 
 use File::Find; 
 use Cwd; 
 my $dir = cwd; 
 print "Listing of $dir\n\n"; 
find ( \&printer, $dir ); 
sub printer {
    my $size=(stat($File::Find::name))[7];
    print qq{$File::Find::name $size\n};
}
---
This gives me something like
Listing of /Users/jan/Sites/janeden/public/comp
/Users/jan/Sites/janeden/public/comp 272
/Users/jan/Sites/janeden/public/comp/.DS_Store 6148
/Users/jan/Sites/janeden/public/comp/index.html 2089
/Users/jan/Sites/janeden/public/comp/test.txt 0
/Users/jan/Sites/janeden/public/comp/internet 544
/Users/jan/Sites/janeden/public/comp/internet/.DS_Store 6148
/Users/jan/Sites/janeden/public/comp/internet/dienste.html 7128
/Users/jan/Sites/janeden/public/comp/internet/geschichte.html 5741
/Users/jan/Sites/janeden/public/comp/internet/index.html 4036
If you get something else (i.e. some output without the file size), it might be due to differences between Unix and Windows filesystem.
----- Original Message -----
From: Ryan Thomas
Sent: 21.04.2004, 13:10 Uhr
>I don't get any errors when running the script, it just doesn't print any
>file size values.
>
>A copy of the output is below:
>
>c:\proggy
>c:\proggy/counter.bak
>c:\proggy/counter.exe
>c:\proggy/counter.pl
>c:\proggy/error.txt
>c:\proggy/filelist.pl
>c:\proggy/filelisting.txt
>c:\proggy/linecount.pl
>c:\proggy/list.txt
>c:\proggy/list2.txt
>c:\proggy/lister.pl
>c:\proggy/orig.pl
>
>Any help appreciated.
>
>Jane
>
>
>----- Original Message ----- 
>From: "Jan Eden" <lists@janeden.org>
>To: "Ryan Thomas" <ryan@valetech.com>; "Perl Lists" <beginners@perl.org>
>Sent: Wednesday, April 21, 2004 12:59 PM
>Subject: Re: Problem with Code
>
>
>Hi Jane,
>
>----- Original Message -----
>From: Ryan Thomas
>Sent: 21.04.2004, 12:18 Uhr
>
>>Hello All
>>
>>I have a script below that lists a directory tree structure (thanks for the
>base
>>code Jan!)and have modified it, unsuccessfully, to add the file size.
>>
>>What have i done wrong ??
>>
>>The output I am looking for is:
>>
>>c:\anydir\foo.txt 1,102
>>
>>code:
>>
>># Reads a directory tree and parses the results
>>
>># use strict;
>>use File::Find;
>>use File::stat;
>>use Cwd;
>
>You should not comment 'use strict;' which will force you to use good
>programming style.
>
>Apart from that, your script works for me. If you want the output mentioned
>above, though, you would have to write (printf formatting left out):
>
>>find ( sub { print qq{$File::Find::name };
>>$size=(stat($File::Find::name))[7];
>>print $size; }
>
>What error messages do you get?
>
>- Jan
>-- 
>There's no place like ~/
>
>
>
-- 
These are my principles and if you don't like them... well, I have others. - Groucho Marx


Relevant Pages

  • Help with fileglob: Unix vs. Windows?
    ... use warnings; ... use strict; ... But this script doesn't do right in Windows: ...
    (perl.beginners)
  • RE: perl script instead of grep
    ... use strict; ... The script was writeen for windows with \\ in the path. ... It should run on a linux box. ... Is ti possible, for compatibility, to use // in windows too? ...
    (perl.beginners)
  • Re: file directory with creation date & dimensions (for photo list
    ... Automatically opens the Tab de-limited text file in Microsoft ... 'If you don't have MS Excel, ... Microsoft MVP [Windows XP Shell/User] ... > this info into a listing? ...
    (microsoft.public.windowsxp.help_and_support)
  • Possible trojan???
    ... Description: Windows NT Session Manager ... >Trojan, here is a good utility to identify all ip traffic ... I'd intended to install it and see what it ... >>smss.exe either listing or established you know its a ...
    (microsoft.public.win2000.security)
  • Re: HDD ( scsi ) vanished from explorer..
    ... But it's listing in device manager -- disk drive list ( ... right pane window. ... >> y'day suddenly HDD3 vanished from windows explorer. ... >> But I rebooted and checked, it's detecting and listing. ...
    (microsoft.public.win2000.hardware)

Loading