Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Finding missing libs in a directory

by Anonymous Monk
on Mar 11, 2011 at 22:08 UTC ( #892756=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a directory which contains many of the following directories inside it.Now I am trying to find all the directories which donot have the corresponding *.so,*.o,*,a in it.Is there a simpler and quick way to achieve this?Appreciate any quick help.

CMA\data\files\arm\so-le-v7 (should have *.so) ama\data\files\arm\so-le-v7-g (should have *.so) media\data\files\arm\o-le-v7 (should have *.o) encdc\data\files\arm\o-le-v7-g(should have *.o) qcp\data\files\arm\a-le-v7(should have *.a) pcn\data\files\arm\a-le-v7-g(should have *.a) If any of the above is missing ,print the directory ...............

Replies are listed 'Best First'.
Re: Finding missing libs in a directory
by jethro (Monsignor) on Mar 11, 2011 at 23:30 UTC
    Use File::Find, for every dir you find, check if the corresponding file is in it.

      Can someone give me a starting point?I am very very new to perl.Basically every directory which starts with "o-le-v7" and "a-le-v7" should have one of *.so,*.o,*.a,if they are not present print the directory

        What have you done so far? Where do you have problems? Do you know how to write a loop? Do you have a perl book at hand or some other documentation to find suitable functions and methods for your problem? Can you write a script that shows what you already know how to do?

        Here a few more pointers:

        If a string starts with some other string, you might use substr() and string equality operator 'eq' or a regular expression, i.e. if ( $x=~/o-le-v7/) { ... }

        To read the contents of a directory, you might use glob() or File::Find (if you want to search subdirectories as well), or readdir()

        With the operator '-d' you can find out if some file is a directory, i.e.  if (-d $file) { ... }

Re: Finding missing libs in a directory
by wind (Priest) on Mar 12, 2011 at 01:54 UTC
    Just use File::Spec and glob
    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"; } } __DATA__ CMA\data\files\arm\so-le-v7 so ama\data\files\arm\so-le-v7-g so media\data\files\arm\o-le-v7 o encdc\data\files\arm\o-le-v7-g o qcp\data\files\arm\a-le-v7 a pcn\data\files\arm\a-le-v7-g a

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://892756]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2017-12-15 23:20 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (444 votes). Check out past polls.