file::find + absolute path

Discussion in 'Perl Misc' started by kielhd, Feb 26, 2004.

  1. kielhd

    kielhd Guest

    Hi NG,
    I am looking into this problem for a while and can't find a solution.
    I need the ***absolute path*** of the files. The following script
    gives me the filenames, but not the path:

    #!C:\Perl\bin\perl.exe -w
    use File::Find;
    $dir = "E:\\";
    find(\&wanted, $dir);

    foreach (@files)
    {
    print ("---> $_\n");
    }

    sub wanted { if ( $_ =~ /\.mp3$/ ) { push (@files, $_); } }

    exit;

    What do I have to do to get the corresponding pathname?

    Any hints are appreciated!

    Best regards, Henning
    kielhd, Feb 26, 2004
    #1
    1. Advertising

  2. kielhd

    fifo Guest

    At 2004-02-26 06:04 -0800, kielhd wrote:
    > Hi NG,
    > I am looking into this problem for a while and can't find a solution.
    > I need the ***absolute path*** of the files. The following script
    > gives me the filenames, but not the path:
    >
    > #!C:\Perl\bin\perl.exe -w
    > use File::Find;
    > $dir = "E:\\";
    > find(\&wanted, $dir);
    >
    > foreach (@files)
    > {
    > print ("---> $_\n");
    > }
    >
    > sub wanted { if ( $_ =~ /\.mp3$/ ) { push (@files, $_); } }
    >
    > exit;
    >
    > What do I have to do to get the corresponding pathname?
    >


    perldoc File::Find

    The section on the wanted function should tell you what you need to
    know.
    fifo, Feb 26, 2004
    #2
    1. Advertising

  3. kielhd

    SomeOne Guest

    Hi Microbe
    If some one answers that, it will be breast feeding, not spoon feeding
    "fifo" <> wrote in message
    news:20040226141822.GB4727@fleece...
    > At 2004-02-26 06:04 -0800, kielhd wrote:
    > > Hi NG,
    > > I am looking into this problem for a while and can't find a solution.
    > > I need the ***absolute path*** of the files. The following script
    > > gives me the filenames, but not the path:
    > >
    > > #!C:\Perl\bin\perl.exe -w
    > > use File::Find;
    > > $dir = "E:\\";
    > > find(\&wanted, $dir);
    > >
    > > foreach (@files)
    > > {
    > > print ("---> $_\n");
    > > }
    > >
    > > sub wanted { if ( $_ =~ /\.mp3$/ ) { push (@files, $_); } }
    > >
    > > exit;
    > >
    > > What do I have to do to get the corresponding pathname?
    > >

    >
    > perldoc File::Find
    >
    > The section on the wanted function should tell you what you need to
    > know.
    SomeOne, Feb 26, 2004
    #3
  4. kielhd <> wrote:

    > I am looking into this problem for a while and can't find a solution.



    Where have you been looking?

    Did you look at the documentation for the functions that you are using?

    That would seem like the very first place to look...


    > use File::Find;



    > sub wanted { if ( $_ =~ /\.mp3$/ ) { push (@files, $_); } }


    > What do I have to do to get the corresponding pathname?



    Access the variable that your function's docs say will contain
    the corresponding pathname.


    > Any hints are appreciated!



    Read the documentation for the functions that you use.

    perldoc File::Find

    ...
    $File::Find::name is the complete pathname to the file.
    ...


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Feb 26, 2004
    #4
  5. kielhd

    Tore Aursand Guest

    On Thu, 26 Feb 2004 06:04:56 -0800, kielhd wrote:
    > I am looking into this problem for a while and can't find a solution. I
    > need the ***absolute path*** of the files. The following script gives me
    > the filenames, but not the path:
    > [...]


    That's because you only care about the filename in your script. Read the
    documentation - 'perldoc File::Find' - for information on how to use that
    excellent module.


    --
    Tore Aursand <>
    "First, God created idiots. That was just for practice. Then He created
    school boards." -- Mark Twain
    Tore Aursand, Feb 26, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    3
    Views:
    19,500
    Sudsy
    Jul 8, 2004
  2. Replies:
    10
    Views:
    3,478
  3. Thomas Guettler
    Replies:
    3
    Views:
    740
    Andrei
    Oct 27, 2003
  4. Nigel Wilkinson
    Replies:
    2
    Views:
    374
    Nigel Wilkinson
    Jul 25, 2005
  5. James Byrne
    Replies:
    3
    Views:
    541
    James Byrne
    Sep 14, 2010
Loading...

Share This Page