Windows 上的 Node.js 符号链接连接已损坏? [英] Node.js symlink junctions are broken on Windows?

查看:31
本文介绍了Windows 上的 Node.js 符号链接连接已损坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,这是代码:

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. i.e., double clicking them gives me an error message

Cuba.txt 无法访问.
文件名、目录名或卷标语法不正确.

Cuba.txt is not accessible.
The filename, directory name, or volume label syntax is incorrect.

怎么会?如何在 Windows 上的 Node.js 中创建符号链接,以使文件正常工作(即其他程序可以读取它们).

How come? How can I create symlinks in Node.js on Windows such that the files work like normal (i.e. other programs can read them).

推荐答案

我记得 NTFS 连接点就像目录,而不是单个文件.

As I remember NTFS junction points act like directories, not individual files.

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

这篇关于Windows 上的 Node.js 符号链接连接已损坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆