【続々々々々々】ディレクトリかどうかの判断

数ヶ月ぶりの続きであるが、まだまだ終わらない。「続」が6つなので7回目ということだ。

ネットワーク上のファイル・ディレクトリに対して、if exist での判断が出来ないということで終わっていたが、何とかなりそうである。

Local DiskUNC nameNetwork Drive
FILEDIRNONEFILEDIRNONEFILEDIRNONE
if exist %~s1
if exist %~s1\
if exist %~s1\\
if exist %~s1\NUL
if exist %~s1\\NUL
if exist %~s1\*
if exist %~s1\\*
if exist "%~1"
if exist "%~1\"
if exist "%~1\\"
if exist "%~1\NUL"
if exist "%~1\\NUL"
if exist "%~1\*"
if exist "%~1\\*"

と、

if exist "%~1\*" echo ディレクトリだ

が使えそうである。空ディレクトリやルートディレクトリでも大丈夫。

同じネットワーク上のファイルでも、UNC形式とドライブにマウントしての場合で、\NULをつけたときの真・偽が変わってくるのがちょっと怪しげ。