xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Microsoft & Node.js All In One

Microsoft & Node.js All In One

Node.js read nested folders path

image

const fs = require("fs").promises;
const path = require("path");

const items = await fs.readdir("stores");
console.log(items); 

const items = await fs.readdir("stores", { withFileTypes: true });
for (let item of items) {
  const type = item.isDirectory() ? "folder" : "file";
  console.log(`${item.name}: ${type}`);
}

function findFiles(folderName) {
  const items = await fs.readdir(folderName, { withFileTypes: true });
  items.forEach((item) => {
    if (path.extname(item.name) === ".json") {
      console.log(`Found file: ${item.name} in folder: ${folderName}`);
    } else {
      // this is a folder, so call this method again and pass in
      // the path to the folder
      findFiles(path.join(folderName, item.name));
    }
  });
}

findFiles("stores");

https://github.com/MicrosoftDocs/node-essentials/blob/main/nodejs-files/index.js

Node.js &fs & node:fs & node:fs/promises

??? node.js modules & npm package ❓magic, index, folder path

import { open } from 'node:fs/promises';

let filehandle;
try {
  filehandle = await open('thefile.txt', 'r');
} finally {
  await filehandle?.close();
}

https://nodejs.org/api/fs.html#fspromisesreaddirpath-options

https://nodejs.org/api/fs.html#fsreaddirsyncpath-options

https://nodejs.dev/en/learn/reading-files-with-nodejs/

chown

import { chown } from 'node:fs';


https://nodejs.org/api/fs.html#fschownpath-uid-gid-callback

chmod

import { chmod } from 'node:fs';

chmod('my_file.txt', 0o775, (err) => {
  if (err) throw err;
  console.log('The permissions for file "my_file.txt" have been changed!');
});

https://nodejs.org/api/fs.html#fschmodpath-mode-callback

Error: EISDIR

Error: EISDIR: illegal operation on a directory, read


Server Error
Error: EISDIR: illegal operation on a directory, read

This error happened while generating the page. Any console logs will be displayed in the terminal window.

// fs

image

image

https://stackoverflow.com/questions/34959038/npm-stuck-giving-the-same-error-eisdir-illegal-operation-on-a-directory-read-a

refs

https://www.cnblogs.com/anonymous-ufo/p/16928886.html



©xgqfrms 2012-2025

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(41)  评论(6编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
历史上的今天:
2021-11-27 How to fix the inaccurate bug of UTC time set by GitHub scheduled tasks All In One
2020-11-27 上海护照办理流程
2020-11-27 vue-cli & plugin:vue/strongly-recommended bug
2020-11-27 知乎 bug
2020-11-27 Google YouTube 前端黑科技
2020-11-27 末日余晖 PC 版 下载
2020-11-27 Apple Support
点击右上角即可分享
微信分享提示