skip to Main Content
node:internal/fs/utils:351
    throw err;
    ^


Error: ENOTDIR: not a directory, scandir './src/functions/.DS_Store'
    at Object.readdirSync (node:fs:1532:3)
    at Object.<anonymous> (/Users/roopa/Desktop/projects/LLbot/src/bot.js:43:6)
    at Module._compile (node:internal/modules/cjs/loader:1255:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
    at Module.load (node:internal/modules/cjs/loader:1113:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47 {
  errno: -20,
  syscall: 'scandir',
  code: 'ENOTDIR',
  path: './src/functions/.DS_Store'
}

part of code which is giving error

const functionFolders = fs.readdirSync(`./src/functions`);
for (const folder of functionFolders) {
  const functionFiles = fs
    .readdirSync(`./src/functions/${folder}`)
    .filter((file) => file.endsWith(".js"));
  for (const file of functionFiles) require(`./functions/${folder}/${file}`);
}

I was trying to make Logs function for my Discord bot and saw that nothing is happening and everything broke after writing code, so I removed all files and code from main ‘bot.js’ file and now it’s giving this error

2

Answers


  1. Chosen as BEST ANSWER

    ok so to remove .DS_Store files I just wrote the following line in the terminal and it worked.

    Also today I had another error regarding 'fs.readdirSync()' function, said that the provided directory cannot be found so to fix that just give the whole path to your folder/file. (For Example, Scroll downwards)

    The line to write in the terminal to remove/delete all .DS_Store files.

    find . -name ".DS_Store" -type f -delete

    Example :

    (BEFORE)

    const commandsFolder = fs.readdirSync('./Commands');
    

    (AFTER)

    const commandsFolder = fs.readdirSync('/Users/roopa/Desktop/projects/LLbot/src/Commands');
    

    Hope it helps :)

    sorry for bad english :')


  2. fs.readdirSync returns all the contents of a directory including files and not just folders. .DS_Store is a special file (not folder) used by Mac to store Finder information.

    In the sample code you pasted, ensure to check whether the item returned by readdirSync() is a directory or not before iterating over the contents in the for loop, something like this

    const functionFolders = fs.readdirSync(`./src/functions`).filter(item => item.isDirectory())
    for (const folder of functionFolders) {
      // rest of the logic
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search