Eugeniu Torica
Eugeniu Torica

Reputation: 7574

Change target for symbolic link in windows

How can I change target of already existing symbolic link. Any solution would work: console, powershell,etc.

Important think is to make this change atomically so solution to delete link and then create a new one do not work for me.

Upvotes: 8

Views: 12268

Answers (4)

Gyan
Gyan

Reputation: 93319

A slight modification of LSemi's method works for me in Windows 7 CMD console

mklink TempLink NewTarget

copy /l /y TempLink OldLink

del TempLink

I've a process that reads OldLink multiple times a second and with this method I'm able to continuously update OldLink to new targets without causing a read error. Strictly speaking, this isn't probably atomic but the time taken to effect the symlink copy must be so small, that it doesn't interfere.

Upvotes: 1

Harry Johnston
Harry Johnston

Reputation: 36348

You could use transactional NTFS. See the following functions:

The downside is that MS are deprecating support for transactions. In particular transactions are not available in the new file system being introduced in Windows Server 2012.

Upvotes: 2

LSerni
LSerni

Reputation: 57418

You can try creating a new symbolic link, and then renaming the new link to overwrite the old.

There are some possibilities mentioned here:

Is an atomic file rename (with overwrite) possible on Windows?

Upvotes: 1

Joey
Joey

Reputation: 354774

This seems to be possible with the ZwFsControlFile function using the FSCTL_SET_REPARSE_POINT control code. At least that's what I gleaned from how Far Manager does it via Process Monitor.

Upvotes: 2

Related Questions