Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
How to search sub-directories for a file, and get the path?

How would I go about doing this?

I am attempting to figure out how to search subdirectories of ./commands, check all folders under it, for a file, and return the path to the file.

//here is where I wish the code to be.

const categories = fs.readdirSync('./commands');

let commandFiles = [];
let commands = [];

for (let folder of categories) {
    let files = null;

    files = fs.readdirSync(`./commands/${folder}`).filter(
        file => file.endsWith('.js')
    );

    const newArray = commandFiles.concat(files)
    commandFiles = newArray
};

if (commandFiles) {
    for (let file of commandFiles) {
        commands.push(file)
    }
}

if (commands) {
    for (let name of commands) {
        // here

        config.commands.set(name, file)
    
        log.info(`[Commands] Loaded.. ${name} ✌️`)
    }
} else {
    log.info('[Commands] No commands have been found.')
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!