统计百度网盘文件个数 V3

本文介绍了一个用于统计百度网盘指定目录下文件数量的实用脚本。通过调用百度网盘API并使用jQuery进行参数解析,该脚本能够递归统计目录下的所有文件数量,并实时显示统计进度及用时。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

继续优化


/********************
*百度文件数量统计 V3
*2018.06.18
*Jackie
********************/


/************
*百度查询接口
http://pan.baidu.com/api/list?
dir=				//查询目录
&num=100000			//分页大小 最大支持99999999999999 默认1000
&page=1				//页码
&order=time			//排序属性
&desc=1				//排序顺序
&clienttype=0
&showempty=0
************/



var root = "";//指定目录,空取当前目录
var maxPageSize=99999999999999; //最多支持这么多,超过此值报错
var dskApi="https://pan.baidu.com/api/list?&num="+maxPageSize+"&page=1&dir=";
var totalCount = 0;
var startTime = new Date();
var clearTimes=0;
var asyncType=false;//true 异步,false 同步
var clearMaxTimes=50;//最大显示行数,超过清一屏
function timeSpan(stime, etime) {
	var usedTime = etime - stime;
	var days = Math.floor(usedTime / (24 * 3600 * 1000));
	var leave1 = usedTime % (24 * 3600 * 1000);
	var hours = Math.floor(leave1 / (3600 * 1000));
	var leave2 = leave1 % (3600 * 1000);
	var minutes = Math.floor(leave2 / (60 * 1000));
	var leave3 = leave2 % (60 * 1000);
	var seconds = Math.round(leave3 / 1000);
	var time ="";
	if(days>0)
	{
		time+=days+"天";
	}
	if(hours>0)
	{
		time+=hours+"小时";
	}
	if(minutes>0)
	{
		time+=minutes+"分钟";
	}
	 
	time+=seconds+"秒";
	 
    return time;  
} 

(function($){
    $.getUrlParam = function (name) {
        var search = document.location.hash;
        var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g");
        var matcher = pattern.exec(search);
        var items = null;
        if (null != matcher) {
            try {
                items = decodeURIComponent(decodeURIComponent(matcher[1]));
            } catch (e) {
                try {
                    items = decodeURIComponent(matcher[1]);
                } catch (e) {
                    items = matcher[1];
                }
            }
        }
		return items;
    }
})(jQuery);

if(root=="")
{
	root=$.getUrlParam("path");
}

function GetFilesCount(fileLists)
{
	var count=0;
	 
	if(fileLists==undefined)
	{
		return 0;
	}
	var ffList=fileLists.filter(function (e) { return e.isdir == 0; });
	count=ffList.length;
	totalCount=totalCount+ffList.length;

	var ddList=fileLists.filter(function (e) { return e.isdir == 1; });
	var dl=ddList.length;
	if(dl>0)
	{
		for (var index=0; index<dl; index++) {  
				 (function(index) {  
						var file=fileLists[index];
						count=count+GetDirFilsCount(file.path);				
					})(index);  
				   
		 }  
	}
	return count;
}

function GetDirFilsCount(dirName)
{
	var dfCount=0;
	$.ajax({
		url: dskApi+''+dirName,
		type: 'get',
		async: asyncType,
		timeout: 3000,          // 设置超时时
		success: function(data) {
			var fileLists = data.list;
			dfCount=GetFilesCount(fileLists);	

			clearTimes++;	
			if(clearTimes==clearMaxTimes)
			{
				console.clear();
				clearTimes=0;
			}
			//console.count();
			console.log("→"+decodeURIComponent(dirName)+":"+dfCount);
			console.log("☋统计目录为:“"+decodeURIComponent(root)+"” 当前计算总数:"+totalCount+" 用时:" +timeSpan(startTime, new Date()));
	}
	});
	return dfCount;
}


GetDirFilsCount(root);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JackieZhengChina

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值