Mark Goland wrote: > > Hi all, Hello,
> I am trying to do directory traversal on NTFS. When I test fileif its a > directory or a regular file. It does not seem to work. -d anf -f test's dont > seem to work as well. Can someone please look over my error. This behavior is described in the readdir entry of perlfunc. perldoc -f readdir readdir DIRHANDLE Returns the next directory entry for a directory opened by `opendir'. If used in list context, returns all the rest of the entries in the directory. If there are no more entries, returns an undefined value in scalar context or a null list in list context. If you're planning to filetest the return values out of a `readdir', you'd better prepend the directory in question. Otherwise, because we didn't `chdir' there, it would have been testing the wrong file. opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!"; @dots = grep { /^\./ && -f "$some_dir/$_" } readdir(DIR); closedir DIR; > #!c:\perl\bin\perl -w use strict; > use Win32::File ; > > &my_trav('.'); ^ The ampersand at the beginning means you want to bypass the subs prototype. > sub my_trav(){ ^^ The parentheses mean that you don't want to accept any arguments for this sub but you obviously do as evidenced by the next line. perldoc perlsub > $DIRNAME.=$_[0]; > print "in dir $DIRNAME\n"; > > opendir DIR,$DIRNAME; You should _always_ verify that opendir was successful. > @dir=readdir DIR; > > foreach $Val(@dir){ > > Win32::File::GetAttributes("$Val", $attr); ^^^^^^ You need the complete path, not just the file name "$DIRNAME/$Val" > print "Direcotry:\t$Val\tattrib=$attr\n" if ( $attr & DIRECTORY); > print "File:\t$Val\tattrib=$attr\n" if ( $attr & NORMAL); > } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]