2

Unfortunately, I'm on Windows and I need POSIX realpath.

Suppose that there's a dirpath variable in a CMD batch script:

FOODIR=D:/tmp/foo/bar/quux

where one or more middle components of the dirpath are symlinks (directory junctions in Microsoft parlance):

[/cygdrive/d/tmp]$ cmd /C dir /Ad /l
 ...
 Directory of D:\tmp
...
2014-12-10  16:44    <SYMLINKD>     foo [D:\storage\foo.canonical]

How to write a function which will transform %FOODIR% into D:/storage/foo.canonical/bar/quux?

Any solutions welcome.

ulidtko
  • 14,740
  • 10
  • 56
  • 88

1 Answers1

0

GetFinalPathNameByHandle worked for me.

Alternatively with Powershell 5+ you may traverse path up and resolve each folder. Check for .LinkType in ('Junction', 'SymbolicLink') and use .Target[0] with optional resolution for relative symlinks.

Community
  • 1
  • 1
Anton Krouglov
  • 3,077
  • 2
  • 29
  • 50