Create symlink on a network drive to a file on same network drive (Win10)

Viewed 466

Problem statement:

I have a python 3.8.5 script running on Windows 10 that processes large files from multiple locations on a network drive and creates .png files containing graphs of the analyzed results. The graphs are all stored in a single destination folder on the same network drive. It looks something like this

Source files: \\drive\src1\src1.txt \\drive\src2\src2.txt \\drive\src3\src3.txt

Output folder: \\drive\dest\out1.png \\drive\dest\out2.png \\drive\dest\out3.png

Occasionally we need to replot the original source file and examine a portion of the data trace in detail. This involves hunting for the source file in the right folder. The source file names are longish alphanumerical strings so this process is tedious. In order to make it less tedious I would like to creaty symlinks to the orignal source files and save them side by side with the .png files. The output folder would then look like this

Output files:

\\drive\dest\out1.png \\drive\dest\out1_src.txt

\\drive\dest\out2.png \\drive\dest\out2_src.txt

\\drive\dest\out3.png \\drive\dest\out3_src.txt

where \\drive\dest\out1_src.txt is a symlink to \\drive\src1\src1.txt, etc.

I am attempting to accomplish this via

os.symlink('//drive/dest/out1_src.txt', '//drive/src1/src1.txt')

However no matter what I try I get

PermissionError: [WinError 5] Access is denied

I have tried running the script from an elevated shell, enabling Developer Mode, and running

fsutil behavior set SymlinkEvaluation R2R:1

fsutil behavior set SymlinkEvaluation R2L:1

but nothing seems to work. There is absolutely no problem creating the symlinks on a local drive, e.g.,

os.symlink('C:/dest/out1_src.txt', '//drive/src1/src1.txt')

but that does not accomplish my goals. I have also tried creading links on the local drive per above then then copying them to the network location with

shutil.copy(src, dest, follow_symlinks = False)

and it fails with the same error message. Attempts to accomplish the same thing directly in the shell from an elevated shell also fail with the same "Access is denied" error message

mklink \\drive\dest\out1_src.txt \\drive\src1\src1.txt

It seems to be some type of a windows permission error. However when I run fsutil behavior query SymlinkEvaluation in the shell I get

Local to local symbolic links are enabled.
Local to remote symbolic links are enabled.
Remote to local symbolic links are enabled.
Remote to remote symbolic links are enabled.

Any idea how to resolve this? I have been googling for hours and according to everything I am reading it should work, except that it does not.

1 Answers

Open secpol.msc on PC where the newtork share is hosted, navigate to Local Policies - User Rights Assignment - Create symbolic links and add account you use to connect to the network share. You need to logoff from shared folder (Control Panel - All Control Panel Items - Credential Manager or maybe you have to reboot both computers) and try again.

Related