To detect whether an object is a file or a directory/folder I used
if exist "%~1\" echo DIR
This should echo DIR only if the object is a directory
however, if the path to the file contains a reparse point/junction,
this test will always return DIR, even if the object is a file:
if exist "dir1\junction\dir2\file.txt\" echo DIR
will always echo DIR
This can be quite confusing if you do not not know that there is a
reparse point in the path.
What seems to work fine is the alternative method
dir /AD %1 | find "<DIR>" > nul
if not errorlevel 1 echo DIR
however this can be slow.
Are there any other such traps with reparse points?
As has been discussed fairly extensively quite some time ago, it is not
that simple
75} How do I detect if an object is a file or a folder?
179284 Oct 21 2006 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html
I am well aware of that resource, it is quite useful, thanks
In fact this is where I got the way I am currently using to detect
directories, namely
dir %1 | find "<DIR>" > nul
if errorlevel 1 ...
I modified the first line to
2>nul dir /AD %1 | find "<DIR>" > nul
in hopes of speeding it up a bit for directories with lots of entries.
But the tips also still contain the solution
if exist "%~1\" (...
which apparently works fairly well as long as the path does not contain
any reparse points, but fails silently if it does.
I found no mention of that in previous discussions about the topic.
So I would suggest adding a warning to that tip.
> But the tips also still contain the solution
> if exist "%~1\" (...
> which apparently works fairly well as long as the path does not contain
> any reparse points, but fails silently if it does.
> I found no mention of that in previous discussions about the topic.
>
> So I would suggest adding a warning to that tip.
Thanks Christoph. I'll add a Message-Id pointer to your contribution.
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip