On Jan 21, Franck Collineau said: >#!/usr/bin/perl -w >$chemin="/home/collineau/tests"; >opendir (DIR,"$chemin") || die " impossible d'ouvrir le répertoire $chemin >$!"; >while ($rep=readdir DIR) >{ > print "$rep\n"; > $a =-d $rep; > print "$a\n"; >}
>Techmedia Broadband home and Startech are directories. >Why $a doesn't return 1 ? Take a good look at the filename stored in $rep. It is merely "." or ".." or "Startech". That means when you do a filetest like -d, Perl does it on ".", or "..", or "Startech". However, while "." and ".." are likely to be found everywhere, "Startech" is not in the directory your program is running in, but rather in /home/collineau/tests. I find that many people routinely forget (or never knew?) that readdir() returns the ENTRIES in a directory -- just the names. If you want a relative path to that file, you must add it yourself. opendir DIR, $path; while (defined(my $file = readdir DIR)) { my $full = "$path/$file"; print "$full: ", -d $full, "\n"; } closedir DIR; Notice the difference? -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]