簡體   English   中英

nodejs fs 路徑和 readdirSync

[英]nodejs fs path and readdirSync

我嘗試在我的應用程序中使用函數 readdirsync。 我想讀取位於我的應用程序根目錄頂部的特殊文件夾。

development
--allure 
----allure-result
--myapproot
----myapp.js

我現在想閱讀文件夾 allure-result 為此我首先使用: watch path = "../allure/allure-results/"

var watchpath = path.join(__alluredir , 'allure-results/');
var dirFiles1 = fs.readdirSync(watchpath);
console.log("Test");
console.log(dirFiles1.length);

然后我嘗試 watch path = "/users/myname/development/allure/allure-results/"

var watchpath = path.join(__watchdir , 'allure-results/');
var dirFiles1 = fs.readdirSync(watchpath);
console.log("Test");
console.log(dirFiles1.length);

該應用程序不會回答這兩個 console.log 行。 只是沉默。 console.log 中沒有錯誤。 看起來 readdirSync 不能正常工作。 我也試過

var dirFiles1 = await fs.readdirSync(watchpath);

文件夾里面有很多文件。 也許這就是問題所在? 希望任何人都可以在這里提供幫助,為什么該函數沒有給出結果。

這是我的文件夾結構..

項目名

|-- app.js

|-- package.json

|-- 實用程序

     |`-- test
          |-- 1.js
          |-- 2.js
          |-- 3.js
   `

|-- package.json

|-- 節點模塊

當我想列出 utils/test/* 下的文件時

const fs=require('fs');
console.log(fs.readdirSync('./utils/test').length) >>> 3

讓我知道,如果這個不適合你!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM