How to display a list of files in a folder recursively, that is, if there is another folder in the folder, then output the files for it and so on. for example

Папка >Файл >Файл 

Must withdraw

 Папка Файл Файл 

If so:

 Папка Папка Файл Файл Файл Файл 

Should output:

 Папка Папка Файл Файл Файл ФАйл 
  • If this is a Node, refer to the readdir - Alexander Lonberg documentation

1 answer 1

Using Node.js :

 const fs = require('fs'); const path = require('path'); function walk(dir_path, indent='') { const INDENT_CHAR = ' '; if (fs.existsSync(dir_path)) { console.log(`${indent}> [${path.basename(dir_path)}]`); fs.readdirSync(dir_path).forEach((item) => { const item_path = path.join(dir_path, item); if (fs.lstatSync(item_path).isDirectory()) { walk(item_path, indent + INDENT_CHAR); } else { console.log(`${indent}${INDENT_CHAR}> ${path.basename(item_path)}`) } }); } } walk('/home/user/Documents/'); 

Node.js tutorial, part 9: working with the file system