Node.js查找当前目录下文件夹实例代码
作者:jimjiayu 时间:2024-04-16 09:50:32
整理文档,搜刮出Node.js查找当前目录下文件夹实例代码,稍微整理精简一下做下分享。
var http = require("http");
var fs = require("fs");
var server = http.createServer(function (req,res) {
//不处理收藏夹小图标
if(req.url == "/favicon.ico"){
return;
}
//files是文件名的数组 表示text这个文件夹下的所有东西,包括文件和文件夹
fs.readdir('./test/',function(err,files){
//声明一个数组存储目录下的所有文件夹
var floder = [];
//从数组的第一个元素开始遍历数组
(function iterator(i){
//遍历数组files结束
if(i==files.length){
console.log(floder);
return;
}
//遍历查看目录下所有东西
fs.stat('./test/'+files[i],function(err,stats){
//如果是文件夹,就放入存放文件夹的数组中
if(stats.isDirectory()){
floder.push(files[i]);
}
iterator(i+1);
})
})(0)
})
});
server.listen(3000,"127.0.0.1");
来源:http://blog.csdn.net/zhongshijun521/article/details/60583554
标签:nodejs,目录
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
计算机程序设计并行计算概念及定义全面详解
2023-02-20 22:35:59
![](https://img.aspxhome.com/file/2023/2/114692_0s.gif)
python txt中的文件,逐行读取并且每行赋值给变量问题
2021-04-28 21:12:02
![](https://img.aspxhome.com/file/2023/1/117341_0s.png)
Python3.4解释器用法简单示例
2022-01-04 10:30:39
利用Python编写一个记忆翻牌游戏
2022-09-24 02:20:54
PyTorch加载预训练模型实例(pretrained)
2021-02-04 15:26:11
Python参数解析模块sys、getopt、argparse使用与对比分析
2021-12-19 17:39:58
![](https://img.aspxhome.com/file/2023/1/80781_0s.png)
在django项目中,如何单独运行某个python文件
2023-04-27 07:37:22
关于pycharm python3.7成功安装dlib库的问题
2022-03-04 04:22:45
![](https://img.aspxhome.com/file/2023/9/68849_0s.png)
Dreamweaver量身打造Wordpress留言板(三)
2009-12-13 18:45:00
![](https://img.aspxhome.com/file/UploadPic/200912/13/1444290-13s.gif)
两大步骤教您开启MySQL 数据库远程登陆帐号的方法
2024-01-16 10:01:35
MySQL做读写分离提高性能缓解数据库压力
2024-01-27 14:36:19
![](https://img.aspxhome.com/file/2023/7/65297_0s.jpg)
python中实现指定时间调用函数示例代码
2021-04-20 07:14:25
PythonPC客户端自动化实现原理(pywinauto)
2022-11-27 02:24:27
![](https://img.aspxhome.com/file/2023/3/95673_0s.png)
Vue watch监听使用的几种方法
2024-05-09 15:08:40
设计哲学与跨界
2009-08-18 12:25:00
mysql双向加密解密方式用法详解
2024-01-15 05:55:02
Python之Pygame的Draw绘图
2022-11-29 18:51:18
python将图片转base64,实现前端显示
2021-04-26 14:03:04
![](https://img.aspxhome.com/file/2023/0/97290_0s.jpg)
python写一个md5解密器示例
2023-05-24 14:45:10
![](https://img.aspxhome.com/file/2023/4/134694_0s.jpg)
Python中Collections模块的Counter容器类使用教程
2021-10-23 07:28:44
![](https://img.aspxhome.com/file/2023/9/70189_0s.png)