How can Perl detect a file if I don't know the exact path to the file?

I am trying to find a file by a specific path / location.

Sample Path - /var/log/<parent1>/<parent2>/<folder>/file 

Now there are two directories <parent1> and <parent2> as shown in the sample path. These two directories have a random name, so their names cannot be predicted. With the exception of these two directory names, each part of the path is known.

I tried doing something like this -

 if ( -e $filePath ) { # Do something here } 

But that does not work. So how to search for a specific file?

Thanks!

+4
source share
1 answer

Use the glob file:

</var/log/*/*/folder/file>

This does the same thing as a shell with a similar pattern.

Or you can use the glob function. perldoc -f glob for details.

+7
source

Source: https://habr.com/ru/post/1369018/


All Articles