New conditionals for directories

May 20, 2008
10,634
81
Syracuse, NY, USA
I don't know if readability is the right word, but there are a number of places (junctions) that you can get to (as CWD) in which you can't see anything.

1582474754930.png


What is the point of the numerous, seemingly badly behaved, junctions in one's profile directory? You can't enter them with Explorer, but you can with a command prompt. You can't read at the top level but if you know the names of things you canread sub directories.

1582475504642.png
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,223
78
Albuquerque, NM
prospero.unm.edu
Not arguing with you, Vince. I've never understood those either.

To the original suggestion: The easiest way to find out whether a directory is readable is to try reading it. The easiest way to find out whether it's writable is to try writing to it — e.g. try creating and deleting a temp file there. My first thought would be to write it as a function, which could then be used in IF, IF, etc. as desired.
 
May 20, 2008
10,634
81
Syracuse, NY, USA
Not arguing with you, Vince. I've never understood those either.

To the original suggestion: The easiest way to find out whether a directory is readable is to try reading it. The easiest way to find out whether it's writable is to try writing to it — e.g. try creating and deleting a temp file there. My first thought would be to write it as a function, which could then be used in IF, IF, etc. as desired.
Writable is the easy one (as you said, just try it). I don't fully understand and I don't know how robust this is, but "EXIST *" seems to be able to tell the difference between an empty directory (where it's true?) and a directory that you can't read (where it's false). Note that "EXIST NUL" doesn't work.

Code:
v:\> if exist "c:\Users\vefatica\Application Data"\* echo foo

v:\> if exist v:\empty\* echo foo
foo
 
May 20, 2008
10,634
81
Syracuse, NY, USA
Similarly @FILES[*] will be at least 2 (. and ..) in a directory which you can read, and 0 in a directory that you can't read.

Note: "EXIST ." is always true