Node traverses the file directory and prints the file

const fs = require("fs")
const path = require("path")



    function traverse(route) {
    
    
        var r = fs.readdirSync(route)
    
        r.forEach(function (element) {
    
            var result = fs.statSync(element)
    
            if (result.isFile()) {
                // console.log(path.extname(element))
                console.log(element)
            }
            else if (result.isDirectory()) {
                traverse(
                    path.resolve(route, element)
                )
            }
        })
    }
    
    var route = path.resolve("./")
    
    traverse(route);

could you tell me where this error is? I haven"t found it after looking at it for a long time.

clipboard.png


first of all, you learn the markdown syntax and deal with the code to be presented, so that it is convenient for others to discuss it in depth.


your code is more than that, can you post it all, so that you can determine where the problem lies


the path is wrong. Change it to this

var result = fs.statSync(route + '/' + element)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-7b8d9f-15996.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-7b8d9f-15996.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?