Python Windows CMD mklink stops working without error message

I want to create symbolic links for each file in a nested directory structure, where all symbolic links will be placed in one large flat folder and now have the following code:

# loop over directory structure:
# for all items in current directory,
# if item is directory, recurse into it;
# else it a file, then create a symlink for it
def makelinks(folder, targetfolder, cmdprocess = None):
    if not cmdprocess:
        cmdprocess = subprocess.Popen("cmd",
                                  stdin  = subprocess.PIPE,
                                  stdout = subprocess.PIPE,
                                  stderr = subprocess.PIPE)
    print(folder)
    for name in os.listdir(folder):
        fullname = os.path.join(folder, name)
        if os.path.isdir(fullname):
            makelinks(fullname, targetfolder, cmdprocess)
        else:
            makelink(fullname, targetfolder, cmdprocess)

#for a given file, create one symlink in the target folder
def makelink(fullname, targetfolder, cmdprocess):
    linkname = os.path.join(targetfolder, re.sub(r"[\/\\\:\*\?\"\<\>\|]", "-", fullname))
    if not os.path.exists(linkname):
        try:
            os.remove(linkname)
            print("Invalid symlink removed:", linkname)
        except: pass
    if not os.path.exists(linkname):
        cmdprocess.stdin.write("mklink " + linkname + " " + fullname + "\r\n")

So, this is a top-down reversal where the folder name is printed first, then subdirectories are processed. If I run it now on some folder, it all just stops after 10 or so symbolic links.

- , . 9 # tag & reencode ChillOutMix. cmd.exe , mklink ChillOutMix.

time.sleep(2) cmdprocess.stdin.write , Python cmd, .

- , ?

+1
2

mklink ?

0

:

if not os.path.exists(linkname):
    fullcmd = "mklink " + linkname + " " + fullname + "\r\n"
    print fullcmd
    cmdprocess.stdin.write(fullcmd)

, . .

mklink arg, .

0

All Articles