Re: Need a list of files in a dir.



Hello ,
in your examples you're opening "files" not dir's , to open a directory use
this instead
opendir(DIR,$dirname) or die $!;
my @content = readdir(DIR);
closedir(DIR);
then to read files inside it ,
for (@content){
print ;
}
that's it , if you need to remove ("." and "..") which means the top
directorys most of time
use it as follow :
opendir(DIR,$dirname) or die $!;
my @content = grep {! /^\./},readdir(DIR);
closedir(DIR);
then again read them using
for (@content){
print;
}
That's it
HTH

On 9/26/05, Tom Allison <tallison@xxxxxxxxxxx> wrote:
>
> Wiggins d'Anconia wrote:
> > Please bottom post...
> >
> > Daniel Kurtz wrote:
> >
> >>Ooh ooh ooh! One I know!
> >>
> >>open(COMMAND, "dir |");
> >>@files = <COMMAND>;
> >>
> >
>
> Well, there's two methods that I use where I can and they are probably
> more portable.
>
> glob works well most of the time:
> @files = </directory/goes/here/*>;
> But it has problems with large numbers of files. And the problems will
> cause it to fail badly.
>
> The other is to opendir and read in a loop.
>
> In either case you need to remove the '.' and '..' entries:
>
> @files = grep {! /^\./} </directory/goes/here/*>
>
> or something like that.
>
> I should warn you, not only is this untested code, but I haven't even
> had my coffee yet.
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
> For additional commands, e-mail: beginners-help@xxxxxxxx
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>


Relevant Pages

  • Re: What did JKR change her mind about, in your opinion, post-OotP? SPOILERS
    ... committing suicide than I do with the appearance of the veil in the ... books. ... Yeah, First he's all OOh Ooh, use my Elf. ... Then he's all, Die V Die. ...
    (alt.fan.harry-potter)
  • Re: Excel slow on saving
    ... she makes a trifle to die for. ... The Chicken Soup recipe failed. ... After opening a file 1.539Kb, I resorted and closed the file ... I have an ME defrag engine on my Win98 machine. ...
    (microsoft.public.excel.newusers)
  • Re: Amusing problem about DC polarity
    ... The problem is to experimentally determine the correct DC polarity ... without opening the box and without letting the box die. ...
    (sci.electronics.design)
  • Re: Amusing problem about DC polarity
    ... The problem is to experimentally determine the correct DC polarity ... without opening the box and without letting the box die. ...
    (sci.electronics.design)
  • Re: Amusing problem about DC polarity
    ... The problem is to experimentally determine the correct DC polarity ... without opening the box and without letting the box die. ...
    (sci.electronics.design)