40 users online (0 members and 40 guests)  


  Results 1 to 2 of 2

Related

  1. Replies: 0
  2. Replies: 2
  3. Replies: 8
  4. Parse HTML    Forum: PHP Forum
    Replies: 4
  5. How to parse lines of a reponse?    Forum: CGI Perl Forum
    Replies: 3
  1. #1
    jontomato's Avatar
    New User

    Status
    Offline
    Join Date
    Jun 2008
    Posts
    1

    Parse partial directory name

    I was wondering how I could find a directory based off of partial knowledge of its name.

    For instance...
    If I know a directory name starts with "directoryName" but the full name is "directoryNameOne" how could I search for this directory and output its entire name.

    Thanks in advance.

  2. #2
    xmassey's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    100

    Re: Parse partial directory name

    Hi,

    Very quick, basic code:

    Code:
    my $dir_path = "path/to/directory/containing/files/directories/to/search";
    my $input = "directoryName";
    opendir(DIR, $dir_path) || die "Cannot open";
    while(DIR){
         if ($_ =~ m/^$input/i) {
              print "$_\n";
         }
    }
    closedir(DIR);
    Chris



Tags for this Thread