0

There are here a few solutions to detect if a given folder is a Symbolic Link...

but how to detect if one of the folders in path is a SymLink...
not only the immediate parent...
but any ancestor folder ???

for example, in the path:

c:\dir1\dir2\dir3\dir4\dir5\dir6\file.txt

if "dir3" is a Symbolic Link how can i detect it

ZEE
  • 2,931
  • 5
  • 35
  • 47

1 Answers1

1

Batch file, tested on windows 10

@echo off
    setlocal enableextensions disabledelayedexpansion

    set "file=c:\dir1\dir2\dir3\dir4\dir5\dir6\file.txt"

    for %%a in ("%file%") do for /f "delims=" %%b in ('
        fsutil hardlink list "%%~fa"
    ') do if "%%~pnxa"=="%%b" (
        echo no link
    ) else (
        echo linked
        echo "%%~pnxa"
        echo "%%b"
    )

It uses the fsutil to retrieve the the real path to the file, checking it against the used path.

MC ND
  • 69,615
  • 8
  • 84
  • 126