Get all files recursively in directories NodejS

前端 未结 10 1259
暖寄归人
暖寄归人 2020-12-14 07:15

I have a little problem with my function. I would like to get all files in many directories. Currently, I can retrieve the files in the file passed in parameters. I would li

10条回答
  •  失恋的感觉
    2020-12-14 07:30

    Packed into library: https://www.npmjs.com/package/node-recursive-directory

    https://github.com/vvmspace/node-recursive-directory

    List of files:

    const getFiles = require('node-recursive-directory');
    
    (async () => {
        const files = await getFiles('/home');
        console.log(files);
    })()
    

    List of files with parsed data:

    const getFiles = require('node-resursive-directory');
     
    (async () => {
        const files = await getFiles('/home', true); // add true
        console.log(files);
    })()
    

    You will get something like that:

      [
          ...,
          {
            fullpath: '/home/vvm/Downloads/images/Some/Some Image.jpg',
            filepath: '/home/vvm/Downloads/images/Some/',
            filename: 'Some Image.jpg',
            dirname: 'Some'
        },
      ]
    

提交回复
热议问题