Question

I found this script that read from directories recursively and i have troubles understanding this line of code :

if ($file eq '.' || $file eq '..')

so if someone could explain this a little bit , and thanks .

Was it helpful?

Solution 2

It tests if file is equal to '.' (current directory) or '..' parent directory. This sort of thing is used when you are searching the directory tree but do not want to process these special files.

Example:

For each file in SomeDirectory:
  if file is current directory, '.', or parent directory ,'..'
    skip
  do something with file
EndFor

OTHER TIPS

This line checks that $file is equal to "." or "..". Those are special filenames in UNIX, meaning “current directory” and “parent directory” respectively.

The readdir function in Perl returns not only the entries in the opened directory, but also directories that represent the currently opened directory itself: ., and the parent directory: ... These are not generally useful for recursive actions on directories, and are handled specially in that code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top