pfaulstich has asked for the wisdom of the Perl Monks concerning the following question:

It appears (much to my surprise), that the file tests such as -e do not work on UNC paths. Is that correct? EG, -e \\\\server\\dir1\\dir2 will fail if I have permissions to see it. If this is true, then how do you recommend that I check for the existence of a UNC path? Thanks! (UPDATING: stupid mistake. file tests work fine w/ UNC paths.)

Replies are listed 'Best First'.
Re: UNC File Tests
by ikegami (Patriarch) on Mar 19, 2010 at 04:11 UTC
    Works for me
    >perl -wle"print -e '\\\\tribble\\c$\\bin' ?1:0" 1 >perl -wle"print -e '\\\\tribble\\c$\\bla' ?1:0" 0 >perl -wle"print -e '\\\\baragon\\c$\\bin' ?1:0" 1 >perl -wle"print -e '\\\\baragon\\c$\\bla' ?1:0" 0

    Mind you, the code you posted gives syntax errors.

    >perl -e"-e \\\\server\\dir1\\dir2" Backslash found where operator expected at -e line 1, near "server\" Backslash found where operator expected at -e line 1, near "dir1\" syntax error at -e line 1, near "server\" Execution of -e aborted due to compilation errors.

    That's not what you meant, right?

      DOH! stupid mistake. I had an extraneous space on the end of the path I was testing with. Yes, indeed the file tests work on a UNC path. (so embarrassing...)