in reply to Is there a Dir/File::Find

Uh, File::Find calls wanted for everything: files, directories, and anything else in there. You have to work at it to ignore those things, rather than include them!

Can you show an example of some code that you thought wasn't finding directories?

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: Is there a Dir/File::Find
by GrandFather (Saint) on Jul 29, 2005 at 03:31 UTC

    Hmmm, yesish. I get the following odd results:

    use File::Find; find (\&ProcessDirTree, './_NewExtensionTemplate'); sub ProcessDirTree { print "Dir: $File::Find::name\n" if -d $File::Find::name; print "File: $File::Find::name\n" unless -d $File::Find::name; } File: ./_NewExtensionTemplate File: ./_NewExtensionTemplate/0_0 File: ./_NewExtensionTemplate/0_0/Inputs File: ./_NewExtensionTemplate/0_0/Inputs/ReadMe''.rtf File: ./_NewExtensionTemplate/0_0/Inputs/Build File: ./_NewExtensionTemplate/0_0/Inputs/Build/build.bld File: ./_NewExtensionTemplate/0_0/Inputs/Build/Build.macros File: ./_NewExtensionTemplate/0_0/Inputs/Build/NotATag.txt

    where I would expect:

    Dir: ./_NewExtensionTemplate Dir: ./_NewExtensionTemplate/0_0 Dir: ./_NewExtensionTemplate/0_0/Inputs File: ./_NewExtensionTemplate/0_0/Inputs/ReadMe''.rtf Dir: ./_NewExtensionTemplate/0_0/Inputs/Build File: ./_NewExtensionTemplate/0_0/Inputs/Build/build.bld File: ./_NewExtensionTemplate/0_0/Inputs/Build/Build.macros File: ./_NewExtensionTemplate/0_0/Inputs/Build/NotATag.txt

    Perl is Huffman encoded by design.
      Within "wanted", you want to use "$_", not "$File::Find::name", because you are chdir'ed down into the directory. Just use "-d" for example, because it defaults to $_.

      So, your code would look like:

      use File::Find; find (\&ProcessDirTree, './_NewExtensionTemplate'); sub ProcessDirTree { print "Dir: $File::Find::name\n" if -d; print "File: $File::Find::name\n" unless -d; }

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        Smacks forehead with palm of hand and wanders red-faced off into the distance muttering "I knew that, I knew that"!

        Thanks merlyn!


        Perl is Huffman encoded by design.