简体   繁体   English

Windows上的Node.js symlink联结断开了吗?

[英]Node.js symlink junctions are broken on Windows?

First, here's the code: 首先,下面是代码:

const FS = require('fs');
const OS = require('os');
const symlinkType = OS.platform() === 'win32' ? 'junction' : 'file';

FS.symlink(target, path, symlinkType, err => {
    if(err) {
        console.error(`Failed to create ${symlinkType} ${path} -> ${target}`);
    } else {
        console.log(`Created ${symlinkType} ${path} -> ${target}`);
    }
})

This spits out a bunch of messages like this: 这样会吐出一堆这样的消息:

Created junction C:\Users\Mark\*snip*\data\Pacific\Midway.txt -> C:\Users\Mark\*snip*\data\Pacific\Pago_Pago.txt
Created junction C:\Users\Mark\*snip*\data\Pacific\Samoa.txt -> C:\Users\Mark\*snip*\data\Pacific\Pago_Pago.txt
Created junction C:\Users\Mark\*snip*\data\Pacific\Ponape.txt -> C:\Users\Mark\*snip*\data\Pacific\Pohnpei.txt

So it looks like it's working. 所以看起来好像正在工作。 I can see the junctions/shortcuts in Explorer: 我可以在资源管理器中看到路口/快捷方式:

But they're all broken. 但是他们都坏了。 ie, double clicking them gives me an error message 即,双击它们给我一条错误消息

Cuba.txt is not accessible. 无法访问Cuba.txt。
The filename, directory name, or volume label syntax is incorrect. 文件名,目录名称或卷标签语法不正确。

How come? 怎么会? How can I create symlinks in Node.js on Windows such that the files work like normal (ie other programs can read them). 如何在Windows上的Node.js中创建符号链接,以使文件正常工作(即其他程序可以读取它们)。

As I remember NTFS junction points act like directories, not individual files. 我记得NTFS交接点的作用就像目录,而不是单个文件。

See https://msdn.microsoft.com/en-us/library/windows/desktop/aa365006(v=vs.85).aspx 参见https://msdn.microsoft.com/zh-cn/library/windows/desktop/aa365006(v=vs.85).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM