Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Listing Files

by vchavan (Initiate)
on Sep 16, 2011 at 10:44 UTC ( [id://926383]=note: print w/replies, xml ) Need Help??


in reply to Re: Listing Files
in thread Listing Files

Thanks By comparison I want to compare their names. and also check if there is any zero byte file and if there is then list it out. First I need to collect all the files (recursively) from two similar directories say Dir_build1 and Dir_Build2 in say 2 arrays and then compare them by name and find out any differences. Then its directory i.e. if difference comes out in Dir_build2 then it should display that Dir_Build 2 have x y z files different than Dir_build1 Could you please help me ?

Replies are listed 'Best First'.
Re^3: Listing Files
by aaron_baugher (Curate) on Sep 16, 2011 at 11:50 UTC

    Honestly, I'd do this with a few command-line tools, rather than Perl, but the concepts would be the same:

    find Dir_build1 Dir_build2 -type f -size 0 >/tmp/zeros find Dir_build1 -type f | sort >/tmp/1 find Dir_build2 -type f | sort >/tmp/2 comm -3 /tmp/1 /tmp/2

    To do it in Perl, I'd use File::Find to recursively scan through each directory, adding the file names to an array (probably a hash, actually) for each, then sort and compare the two. During the scans, I'd also build a list of zero-byte files, to avoid scanning through them twice, of course.

Re^3: Listing Files
by dreadpiratepeter (Priest) on Sep 16, 2011 at 11:48 UTC
    Why don't you post what you have tried? Then we can help you fix it. This is not a code writing service and the posts above should be enough to get you started.


    -pete
    "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
      use strict; use warnings; use File::Find; find({ wanted => \&process_file, preprocess => \&preprocess, no_chdir +=> 1 }, @ARGV); #find({ wanted => \&process_file, no_chdir => 1 }, @ARGV); sub process_file { @List = (); if (-f $_) { print "This is a file: $_\n"; push(@List,$_); } else { print "This is not file: $_\n"; } return @List; } sub preprocess { print "pre-processing @_\n"; # never see this return sort @_; } @DIRLIST = @List; print "@DIRLIST\n";

      I am trying to return List of Files from File:Find to main Module in @DIRLIST But do not know if it is possible to return a value from wanted sub in File:Find to main sub

        Just create your list variable in the main scope of your script, so it'll be in scope inside the sub:

        my @list; find( \&wanted, '.'); say for @list; sub wanted { return unless -f; push @list, $File::Find::name; }
Re^3: Listing Files
by zentara (Archbishop) on Sep 16, 2011 at 16:37 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://926383]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-24 22:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found