How to get the first file with a .txt extension in a directory with nodejs?

后端 未结 5 1036
感动是毒
感动是毒 2021-02-20 14:06

The directory all my files are in is: \'/usr/home/jordan\' and I have many files under there (in the directory itself, but one file that is named with a .txt extension.

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-20 14:38

    The lazy solution:

    npm install --save readdir
    

    and then

    const {read} = require('readdir');
    read("/usr/home/jordan", "**/*.txt", (err, paths) =>
        console.log(paths)
    );
    

提交回复
热议问题