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

i am having a directory
DIR1.
it contains following files and sub directories
text1.txt
result.txt
DIR2
inside DIR2 again i have some files like
data.file
data2.file
now i want to find files of type .file inside DIR2 without changing to that directory. i mean while i have my current working directory as DIR1 and i find and store all files in DIR2 in a array say @array1
  • Comment on find files ina Directory while not changing to it

Replies are listed 'Best First'.
Re: find files ina Directory while not changing to it
by Zaxo (Archbishop) on Mar 16, 2005 at 05:40 UTC

    my @array1 = glob 'DIR2/*.file';

    After Compline,
    Zaxo

Re: find files ina Directory while not changing to it
by perlsen (Chaplain) on Mar 16, 2005 at 05:48 UTC

    Hi, just try this

    my @files = grep{/\.file$/} readdir(DIR2);
Re: find files ina Directory while not changing to it
by jbrugger (Parson) on Mar 16, 2005 at 05:35 UTC
      ya , this is a way to find all files in directory bit i want to store in array only files with particular extension, say all .file type files
        That's the part you could try to search for yourself. i'm not going to write code for you, i point to a direction you could search for. (and learn perl this way)
        If a simple thing like reading a dir, and or changing / adding the filnames to an array is to hard for you, i will help.
        But if you don't want to put any effort in searching for examples, show what you tried till now, i don't even want to help.
        A reply falls below the community's threshold of quality. You may see it by logging in.
Re: find files ina Directory while not changing to it
by gopalr (Priest) on Mar 16, 2005 at 14:19 UTC
Re: find files ina Directory while not changing to it
by manav (Scribe) on Mar 22, 2005 at 10:43 UTC
    perl -MFile::Find -e 'find(sub{/\.file/&&print($File::Find::name)},"./ +DIR1")'