Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Finding directory paths for missing objs

by Anonymous Monk
on Mar 13, 2011 at 01:06 UTC ( [id://892883]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Basically my goal is for any directory path that matches "o-le-v7","a-le-v7","o-le-v7-g" and "a-le-v7-g" in the end,and then check if the contents of these matching directories contains one of *.so,*.o,*.a ,if none of them are present,print the directory path.How do i change the below script to do that?
#!/usr/bin/perl -w use strict; use warnings; use File::Spec; use strict; use warnings; while (<DATA>) { chomp; my ($dir, $ext) = split ' '; my $path = File::Spec->catfile($dir, "*.$ext") . "\n"; if (! glob($path)) { print "No '$ext' in $dir\n"; } }

Replies are listed 'Best First'.
Re: Finding directory paths for missing objs
by Khen1950fx (Canon) on Mar 13, 2011 at 05:10 UTC
    I tried this:
    #!/usr/bin/perl use strict; use warnings; use File::Util; use File::Spec; my @dirs = shift @ARGV; my($f) = File::Util->new(); (@dirs) = $f->list_dir( @dirs, '--dirs-only', '--no-fsdots', '--with-paths'); foreach my $dir(@dirs) { foreach ($dir) { my (@ext) = ('*.so', '*.o', '*.a'); my $path = File::Spec->catfile($dir, "*.@ext") . "\n"; if (not glob($path)) { print "No @ext in $dir\n"; } else { print "OK\n"; } } }
    Update: replaced if ($dir) with foreach ($dir)

      i need to search 1. recursively and 2.i only want to search in directories that end with "o-le-v7,o-le-v7-g,a-le-v7,a-le-v7-g"

Re: Finding directory paths for missing objs
by philipbailey (Curate) on Mar 13, 2011 at 16:51 UTC

    As suggested by jethro in your previous thread (Finding missing libs in a directory), File::Find can achieve your requirements:

    #!/usr/bin/perl use warnings; use strict; use File::Find; find(sub { if (-d and /[oa]-le-v7(-g)?$/) { print "No matching files in $File::Find::dir/$_\n" unless +grep { /\.(o|a|so)$/ } glob "$_/*"; } }, "testdir" );

      what is "test dir" for?does the script search for recursive directories?.I removed "test dir" and running into the following error invalid top directory at C:/Perl/lib/File/Find.pm line 295.

        Never mind,I figured out.Thanks for your help.

      what is "test dir" for?does the script search for recursive directories?

        "testdir" is the directory where I created test directories and files. You should replace with the root of the directory tree you wish to search. Yes, File::Find does perform a recursive search.

Re: Finding directory paths for missing objs
by Anonymous Monk on Mar 13, 2011 at 02:12 UTC

    I tried to get the list of directory paths that are required but running into some errors with the above code.Can any one advise?

      Try continuing your questions in the same thread that provided you with that code Finding missing libs in a directory.

      If you're going to get your project done for you, might as well be obvious about it. The monks here will know anyway, and that way they have all the information instead of just part of your problem.

        Sorry about that,I thought no one is going to look into that thread for any further queries.Also I tried to use the sample code but running into errors.Can anyone help in either of the steps?Again am a perl dummy

        1.Find directories ending with o-le-v7","a-le-v7","o-le-v7-g" and "a-le-v7-g 2.look in those directories for the file extensions

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-03-29 14:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found