in reply to How to test if a file is readable on Win64?
In my experience, there are so many possible factors that could influence “the ability to access a file,” and so many ways for the system to (rudely) inform you that you can’t, that you’re going to have to use logic that can handle the possibility that an exception might be thrown. The simplest way to do that in Perl is with the eval { ... } construct. Wrap the entire thing up in a subroutine which will always survive and which will return True or False. Within that subroutine, do this ... attempt the test, and if the test succeeds without an exception, use the result that it obtained. If it does not, catch the exception, squash it, and say that access is denied. Don’t attempt to write logic that avoids the possibility of an exception being thrown, because that probably can’t be avoided in the general case.
Many CPAN modules already incorporate this kind of logic.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to test if a file is readable on Win64?
by Anonymous Monk on Mar 12, 2014 at 11:03 UTC | |
|
Re^2: How to test if a file is readable on Win64?
by eyepopslikeamosquito (Archbishop) on Mar 12, 2014 at 10:50 UTC |