You said that you want to work on subfolders. The
next if -f $_;
checks if the current directory entry (contained in $_) is a regular file (as opposed to directories or folders in MS parlance), and, if it is, goes directly to the next directory entry in the list. This way, the script will only work on subdirectories.
Update: as correctly pointed out below by Happy-the-monk, the code above will filter out only plain files (I used the words "regular files" to mean that). So that it is not completely accurate to write, as I did above, that the script will only work on subdirectories, since there can be other entities than just plain files and subdirectories. And it would be better to identify real directories with something like next unless -d $_;. Thank you, Happy-the-monk, for the added accuracy.
| [reply] [d/l] [select] |
This way, the script will only work on subdirectories.
it will only work on files that are not "plain files", but will still include unwanted entities like symlinks, named pipes, sockets, block and character files.
Instead of next if -f $_; which is not that accurate, it is much better to use the already suggested next unless -d $_; which does the trick of doing no more and no worse of skipping everything that's not a directory.
Cheers, Sören
Créateur des bugs mobiles - let loose once, run everywhere.
(hooked on the Perl Programming language)
| [reply] [d/l] [select] |
Yes, I absolutely agree with you, Happy-the-monk, I would also use next unless -d $_; if I wanted to get only directories. And probably add a regular expression or something else to filter out the . and .. directories. Here, I only wanted to briefly answer the question in simple terms, and I had not seen that other answers to the original question also took up this point.
| [reply] [d/l] [select] |