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

Hello, I'm trying to get a recursive listing of files in a directory. I now have a file with listing in the following format: c:\dir1\dir2\dir3\file.txt. I need to remove everything before the file name to end up with a file contains only file names. Any suggestion Thanks

Replies are listed 'Best First'.
Re: Search and replace
by doc (Scribe) on Oct 02, 2001 at 22:55 UTC

    Yes use File::Find but this will do what you want to your path string:

    $path = "c:\\foo\\bar\\perl.exe"; my($dir,$file) = $path =~ m/(.*\\)(.*)/; print "$dir | $file";

    doc

    print(s<>ecode?scalar reverse :p)

      I tried it and it worked perfectly, Thanks
Re: Search and replace
by Desdinova (Friar) on Oct 02, 2001 at 23:10 UTC
    Or for a real simple method you could try File::BASENAME which will just convert those entries into just the filenames. the link has plenty of examples.
Re: Search and replace
by Masem (Monsignor) on Oct 02, 2001 at 22:56 UTC
    It's probably much much much much easier to start with File::Find, which can automagically search a directory recursively, and which gives you only the file name (sans path, though that can be determined as well) for each file.

    However, if you have this file already, one way is to simply do a regex such as s|^.*\([^\]+)$|$1| on each line.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    It's not what you know, but knowing how to find it if you don't know that's important

Re: Search and replace
by silent11 (Vicar) on Oct 02, 2001 at 22:55 UTC
    it looks like you are in windows ... open up a command prompt and 'dir /b >out_file.txt' . This should give you the list you want.

    update : for recursive
    dir /b /s > out_file.txt