首页 > 编程语言 >Microsoft & Node.js All In One

Microsoft & Node.js All In One

时间:2022-11-27 21:56:14浏览次数:67  
标签:Node node fs js item https path Microsoft

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

<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/3xm7spsmtRg?start=327" title="YouTube video player" width="560"></iframe>

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

refs

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.


image

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



©xgqfrms 2012-2021

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

原创文章,版权所有©️xgqfrms, 禁止转载

标签:Node,node,fs,js,item,https,path,Microsoft
From: https://www.cnblogs.com/xgqfrms/p/16930760.html

相关文章

  • ApiJSON简单使用示例
    1{2"[]":{3"query":2,4"User":{5"@column":"id,name"6},7"count":5,8"@order":......
  • JS的深浅拷贝
    基本数据类型:number、string、boolean、null、undefined引用数据类型:object、function、array存储位置的不同基本数据类型:将值存储在栈中,栈中存放的是对应的值......
  • js原型和原型链
    目录原型和原型链原型原型链原型和原型链原型在理解之前,明白一个前提,js也是有类的,也可以定义方法和构造函数隐式原型:对象的_proto_属性(里面有类定义的方法,且这个属性每......
  • jquery009-js执行的先后顺序
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>Title</title></head><bodystyle="width:980px;margin:0auto"><h1>#一,当页面框架......
  • leetcode 56. 合并区间 js实现
    以数组 intervals 表示若干个区间的集合,其中单个区间为 intervals[i]=[starti,endi] 。请你合并所有重叠的区间,并返回 一个不重叠的区间数组,该数组需恰好覆盖输入......
  • 前端开发node npm管理常用命令
    要安装NVMnode版本管理工具需要卸载已经安装的node,nvm的好处可以切换不同的nodejs版本,兼容老项目的node版本较低安装注意事项:用管理员执行命令,不然会出......
  • vs2008 调试js
    面对一大段的JavaScript脚本,以前总是会很头疼,找不到调试这些代码的方法。如果出现什么错误或异常,总是要从头分析,然后插入很多Alert(),调试起来很麻烦。VisualStudio2008中J......
  • 解决fastjson内存对象相互应用导入json字符串出现错误问题
        日常在使用FastJson的时候可能很少会遇到这种问题。比如:我们在一个对象中存在一个集合属性对象这个集合属性对象元素属性也同样存在集合属性那么在使用toJSONSt......
  • Prometheus监控之node_exporter
    一、概述1、概述Exporter是Prometheus的指标数据收集组件。它负责从目标Jobs收集数据,并把收集到的数据转换为Prometheus支持的时序数据格式。和传统的指标数据收集组件不同......
  • 基于Servlet+jsp+mysql开发javaWeb学生管理系统(学生信息、学生选课、学生成绩、学生
    你知道的越多,你不知道的越多点赞再看,养成习惯文章目录​​一、开发背景​​​​二、需求分析​​​​三、开发环境​​​​四、运行效果​​​​五、开发流程​​​​工......