On 10/18/07, Joseph L. Casale <[EMAIL PROTECTED]> wrote: > I am needing to perform some work on files located in a directory. I am > reading > the contents of the directory in and but need to filter what's read in. So > far I can > filter out the "." and ".." but I need to add two more cases. I need to make > sure > none of the entries in the array are directories or files with extensions. > > Here is what I have: > > opendir DIR, $InDir or die "cannot open dir $InDir: $!"; > my @files = grep { $_ ne '.' && $_ ne '..' } readdir(DIR); > closedir(DIR); > foreach(@files){ > print $_,"\n"; > } > > Can anyone point me to a possible approach?
That's a good start. To check whether a file name ends with an extension, you probably just need to see whether the string contains a dot, yes? Even if you mean something different by "extension", the answer to this kind of question is generally a pattern match in Perl. To find out about the filesystem object the name refers to (in this case, to find out whether or not it's a directory), one common way is with a filetest (in this case, -d). But the catch is that filetests check in the current directory, unless you give a full pathname. So you can either assemble a full pathname as the parameter of -d, or you can use chdir() to change to the appropriate directory before using -d. Does that get you any closer? Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/