another directory search, yet many subdirs

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default another directory search, yet many subdirs

    People of the Perl,

    I am in need of some help! Here is the info you need for my samba mount
    points.

    directories: ~emstat/win32/backup/012004155140/pc*,
    ~emstat/win32/backup/01210415175/pc*, ~emstat/win32/pc*
    files: under each of these subdirs, pc[#####], I have "training
    2001.eml" files ( NOTE THE SPACE ) that I need deleted!
    so far this is what I have for my perl program

    /usr/bin/perl -w
    use strict;

    # Open dirs and search for string

    $emdir="/home/emstat/win32/backup/012004155140";
    $emdir2="/home/emstat/win32/backup/012104151751";
    $emdir3=
    opendir(DEREK, "$emdir")
    || die "cannot open directory $!";
    opendir(SMITH, "$emdir2")
    || die "cannot open directory $!";

    while (defined ($readdir = DEREK))


    My questions are how can I have this search recursively down under all the
    pc#### subdir names?
    Can I create a scalar like "/home/emstat/win32/backup/012004155140/pc*" so
    it will store all the pc subdirs?
    Can I use reg exp such as a range of pc80[0-9] pc13[0-9] ?

    please help!

    thank you,



    Derek B. Smith
    OhioHealth IT
    UNIX / TSM / EDM Teams


    DBSMITH@OhioHealth.com Guest

  2. Similar Questions and Discussions

    1. Active Directory Search fails ("The directory service is unavailab
      Hi all, I'm having one of those nerve wrecking errors, when trying to perform a simple search in an Active Directory. The objective of the code...
    2. Google groups email spider,Auction software, Directory PPC search engine software, email spiders - 4
      Free download full version , all products from Mewsoft dot com http://netauction8.url4life.com/ Groupawy --------------- Google Groups Email...
    3. Free Health, Fitness, Leisure Directory - are you on it? do you need it? Get listed or search it for free.
      List your health business on the health directory at no cost. Browse and find a practitioner, therapist, gym, spa etc... 1/4 Million hits in 7...
    4. Directory Search
      I need help and guidence towards learning material to build a directory search utility into my asp.net page. I have a Directory called "Trusses"...
    5. how to reference assemblies from web.configs in subdirs?
      Hello, I was wondering how I can reference assemblies from web.config files residing in subdirectories without having to create a new project for...
  3. #2

    Default RE: another directory search, yet many subdirs

    David,

    under each of these suddirs, I need all the eml files deleted but there
    are thousands of them and the actual file name is "training 2001.eml"
    so my questions still remain,

    Can I have this search recursively down under all the pc#### subdir names?
    Can I create a scalar like "/home/emstat/win32/backup/012004155140/pc*" so
    it will store all the pc subdirs?
    Can I use reg exp such as a range of pc80[0-9] pc13[0-9] ?

    Derek B. Smith
    OhioHealth IT
    UNIX / TSM / EDM Teams
    614-566-4145





    "Wagner, David --- Senior Programmer Analyst --- WGO"
    <fedex.com>
    02/16/2004 06:02 PM


    To: <com>, "Perl Beginners" <org>
    cc:
    Subject: RE: another directory search, yet many subdirs


    com wrote: 

    It si not clear in my mind the setup you have. The
    process you want to use is probably File::Find which comes as standard portion of all Perl installs. If I could picture
    the setup in my mind, I could give you a better picture of what to do.

    Sorry.
    Wags ;) 



    ************************************************** ********
    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.
    ************************************************** **************




    DBSMITH@OhioHealth.com Guest

  4. #3

    Default RE: another directory search, yet many subdirs

    <snip>
    under each of these suddirs, I need all the eml files deleted but there

    are thousands of them and the actual file name is "training 2001.eml"
    so my questions still remain,

    Can I have this search recursively down under all the pc#### subdir
    names?
    </snip>

    File::Find will do what you need. Google can help you find some good
    examples.

    Matt Guest

  5. #4

    Default Re: another directory search, yet many subdirs

    Derek Smith wrote: 

    Hi Derek.

    I think I would use File::Find twice: first to find all the /pc* directories
    and then to find all the *.eml files beneath them. The program below is untested
    but should be close to the mark, but it leaves the list of eml files in an array.
    (Best test it before you actually delete the files eh!).

    HTH,

    Rob



    use strict;
    use warnings;

    use File::Find;

    my @dirs = qw(
    /home/emstat/win32/backup/012004155140
    /home/emstat/win32/backup/01210415175
    /home/emstat/win32
    );

    my @pcdirs;

    find(
    sub {
    if (-d and /[^.]/) {
    push @files, $File::Find::name if /^pc/i;
    $File::Find::prune = 1;
    }
    },
    @dirs);

    my @emls;

    find(
    sub {
    if (-f) {
    push @emls, $File::Find::name if /\.eml$/i;
    }
    },
    @pcdirs);



    Rob Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139