Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

打开指定文件夹 #1

Closed
Hunlongyu opened this issue Jun 14, 2022 · 4 comments
Closed

打开指定文件夹 #1

Hunlongyu opened this issue Jun 14, 2022 · 4 comments

Comments

@Hunlongyu
Copy link

看了一下好像没有打开文件夹的功能

fs.openDir(path) {}

可以增加这个功能吗?

@xuld
Copy link
Member

xuld commented Jun 14, 2022

你是指读取文件夹下的所有文件吗?

如果只读取直接的一级,用 fs.readDir('path/to/dir')

如果希望遍历每一级,用

fs.walk('path/to/dir', { 
   dir(p){ console.log(p) },
   file(p){ console.log(p) },
})

多数情况你可能只需要遍历所有文件,可以用 fs.glob('dir/**/*.{js,ts}') 快速扫描所有文件

@Hunlongyu
Copy link
Author

Hunlongyu commented Jun 15, 2022

哈哈,不是读取文件夹里的文件,就是单纯的打开文件资源管理器。

应用场景如:

  1. 打开下载文件所在的目录
  2. 打开自动保存的文件所在的目录

@xuld
Copy link
Member

xuld commented Jun 15, 2022

这个不属于fs层的功能,你需要调用shell命令,可以用这个:

var {exec} = require('tutils/process')

var dir = `C:\\Program Files`
exec(`explorer "${dir}"`)

@Hunlongyu
Copy link
Author

Hunlongyu commented Jun 15, 2022

1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants