简体   繁体   English

无法在文件资源管理器中打开子目录? -Node.js

[英]Can't open subdirectory in File Explorer? - Node.js

I can't figure out why I can't open a subdirectory of "My Documents" in Node.js. 我不知道为什么无法在Node.js中打开“我的文档”的子目录。

My current code: 我当前的代码:

function fileExplorer() {
    var spawn = require('child_process').spawn,
    child    = spawn('C:\\Windows\\explorer.exe', 
    ["%userprofile%\\documents"]);
  }

Works completely fine to fire up the user's "My Documents" folder. 完全可以启动用户的“我的文档”文件夹。 However, if I want to open up a directory inside of "My Documents" like say "My Documents/Extra Stuff" the following doesn't work: 但是,如果我想在“我的文档”中打开一个目录,例如说“我的文档/其他材料”,则以下操作将无效:

function fileExplorer() {
    var spawn = require('child_process').spawn,
    child    = spawn('C:\\Windows\\explorer.exe', 
    ["%userprofile%\\documents\\extra stuff"]);
  }

What am I missing? 我想念什么? Forgive me if something is wrong with what I'm asking, I have a design oriented brain and am more familiar with HTML, CSS and some Javascript. 如果我的要求有问题,请原谅我,我有一个面向设计的头脑,对HTML,CSS和一些Javascript更熟悉。

您可以在process.env.USERPROFILE下的代码中访问%USERPROFILE%环境变量,因此可以使用path.join(process.env.USERPROFILE, 'Documents/extra stuff')使它起作用path.join(process.env.USERPROFILE, 'Documents/extra stuff')

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

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