ss-get-files

1.0.0 • Public • Published

const fs = require('fs') const path = require('path') function isFile(path){ return fs.lstatSync(path).isFile() } function isDirectory(path){ return fs.lstatSync(path).isDirectory() } function callback(file, regex, arr) { let ext = path.extname(file) if(regex.test(ext)){ arr.push(file) } }

dir   路径(C:\Users\user\Desktop)
regex  正则
  • 图片 /.jpg|.png|.gif|.jpeg/i
  • 音乐 /.mp3/i module.exports = function walk(dir, regex){ var files = fs.readdirSync(dir); var fileArr = [] files.forEach(v=>{ if(!v.startsWith('.')){ let tmp = path.join(dir); if(isFile(tmp)){ callback(tmp, regex) }else if(isDirectory(tmp)){ walk(tmp) } } }) return fileArr }

Readme

Keywords

none

Package Sidebar

Install

npm i ss-get-files

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

1.84 kB

Total Files

3

Last publish

Collaborators

  • sun142725