我尝试复制字体与nodejs v14.17.0
到%localappdata%\Microsoft\Windows\Fonts
,当尝试与提示我没有问题
copy /B "Haloha Free Trial.ttf" /V %localappdata%\Microsoft\Windows\Fonts\
1 file(s) copied.
字符串
但是当尝试使用nodejs时,我遇到了这个问题
[Error: EPERM: operation not permitted, copyfile 'D:\dev\test\javascript\font\Haloha Free Trial.ttf' -> 'C:\Users\omen\AppData\Local\Microsoft\Windows\Fonts'] {
errno: -4048,
code: 'EPERM',
syscall: 'copyfile',
path: 'D:\\dev\\test\\javascript\\font\\Haloha Free Trial.ttf',
dest: 'C:\\Users\\omen\\AppData\\Local\\Microsoft\\Windows\\Fonts'
}
型
这是我的代码
let options = process.argv.slice(2);
console.log(options[0]);
console.log(process.env.LOCALAPPDATA);
const locallAppdata = process.env.LOCALAPPDATA;
const fs = require('fs');
fs.copyFile( options[0], locallAppdata+'\\Microsoft\\Windows\\Fonts\\', (err) =>{
if(err) throw err;
console.log( argv[0] + " was copied ");
});
型
如何解决?
2条答案
按热度按时间whlutmcx1#
根据官方文档fs.copyFile
在dest中,不仅需要目标目录,还需要目标文件名**。
字符串
在这种情况下,dest='localAppdata +'\Microsoft\Windows\Fonts\'+options[0]
型
qnakjoqk2#
将文件从一个目录递归复制到另一个目录
字符串