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

Hi Monks,
Iam new to perl. I want to find the xml file in a path, for this iam using File::Find::Rule. In that path some value will change. The below is the path:

my $serpath="D:\\eproof\\htdocs\\load\\work";

In the above path "load" will change. So i used the below:

my $serpath="D:\\eproof\\htdocs\\*\\work";

But i did't get the result.

Any body help me in this..
Regards, Mythili B

Replies are listed 'Best First'.
Re: How to find the path
by Anonymous Monk on Jun 08, 2009 at 03:44 UTC
    Where is your code?
      this is i tried.

      my @xmlfile = File::Find::Rule->file()
      ->name( '*.xml')>br> ->in( "$serpath" );
        in only works for directory names, not wildcards. I suggest you try finding all directories in D:\\eproof\\htdocs first, then searching in those.
      this is i tried.

      my @xmlfile = File::Find::Rule->file()
      ->name( '*.xml')
      ->in( "$serpath" );
        If
        my $serpath="D:\\eproof\\htdocs\\*\\work";
        use
        my @xmlfile = File::Find::Rule->file() ->name( '*.xml') ->in( glob $serpath );
        Here is a self-contained example (you need write permission in current directory)
        #!/usr/bin/perl -- use strict; use warnings; use Shell::Command qw( rm_rf touch mkpath ); use File::Find::Rule; use File::Spec::Functions; my $serpath = './temptest1'; # no trailing slash my $work = 'work'; my $time = int rand 20; mkpath( catfile( $serpath, $time, $work ) ); touch( map { catfile( $serpath, $time, $work, "$_.xml" ) } 1 .. 2 ); #touch(catfile( $serpath, $time, $work, "$_.xml" )) for 1 .. 2; { my @dirs = File::Find::Rule->directory->name($work)->in($serpath); print "dir $_\n" for @dirs; my @xmlfile = File::Find::Rule->file->name('*.xml')->in(@dirs); print "file $_\n" for @xmlfile; } print "wow $_\n" for File::Find::Rule->file->name('*.xml') ->in( glob catfile( $serpath, '*', $work ) ); mkpath("$serpath/$time/$work"); rm_rf('temptest1'); __END__ C:\>perl file.find.rule.pl dir temptest1/3/work file temptest1/3/work/1.xml file temptest1/3/work/2.xml wow temptest1\3\work/1.xml wow temptest1\3\work/2.xml C:\>perl file.find.rule.pl dir temptest1/15/work file temptest1/15/work/1.xml file temptest1/15/work/2.xml wow temptest1\15\work/1.xml wow temptest1\15\work/2.xml