Node.js:如何在没有上传文件列表的情况下检查文件夹是否为空 [英] Node.js: How to check if folder is empty or not with out uploading list of files

查看:212
本文介绍了Node.js:如何在没有上传文件列表的情况下检查文件夹是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Node.js

我要检查文件夹是否为空?一种选择是使用 fs.readdir ,但是它将整个文件加载到一个数组中。
我的文件夹中有超过10000个文件。仅检查文件夹是否为空,加载文件名没有用。因此,正在寻找替代解决方案。

I want to check if folder is empty or not? One option is to use fs.readdir but it loads whole bunch of files into an array. I have more than 10000 files in the folder. Loading files name is useless just to check if folder is empty or not. So looking for alternate solution.

推荐答案

如何使用本机节点 fs 模块 http://nodejs.org/api/fs.html#fs_fs_readdir_path_callback 。它是 readdir readdirSync 函数,为您提供所有包含的文件名数组(除外) 。)。如果长度为 0 ,则目录为空。

How about using nodes native fs module http://nodejs.org/api/fs.html#fs_fs_readdir_path_callback. It's readdir and readdirSync functions provide you with an array of all the included file names (excluding . and ..). If the length is 0 then your directory is empty.

这篇关于Node.js:如何在没有上传文件列表的情况下检查文件夹是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆