手机网站好还是h5好,专业的南昌网站建设,wordpress控制面板,微信开店哪个平台好最近需要统计百度网盘里文件的数量#xff0c;百度网盘又没有提供这样的功能#xff0c;因此之前自己写了段脚本进行查验#xff0c;见《利用浏览器调试功能 计算 百度网盘》。之后发现每个目录最多文件数只有1000#xff0c;因此研究了哈百度的接口#xff0c;重新对脚本…最近需要统计百度网盘里文件的数量百度网盘又没有提供这样的功能因此之前自己写了段脚本进行查验见《利用浏览器调试功能 计算 百度网盘》。之后发现每个目录最多文件数只有1000因此研究了哈百度的接口重新对脚本进行了修改。具体见代码
/********************
*百度文件数量统计 V2
*2018.06.15
*Jackie
********************//************
*百度查询接口
http://pan.baidu.com/api/list?
dir //查询目录
num100000 //分页大小 最大支持99999999999999 默认1000
page1 //页码
ordertime //排序属性
desc1 //排序顺序
clienttype0
showempty0
************/var root ;//指定目录空取当前目录
var maxPageSize99999999999999; //最多支持这么多超过此值无效
var dskApihttps://pan.baidu.com/api/list?nummaxPageSizepage1dir;
var totalCount 0;
var startTime new Date();
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(days0){timedays天;}if(hours0){timehours小时;}if(minutes0){timeminutes分钟;}timeseconds秒;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 count0;var flfileLists.length;for (var index0; indexfl; index) { (function(index) { var filefileLists[index];if(file.isdir0){count;totalCount;}else if(file.isdir1){countcountGetDirFilsCount(file.path);}})(index); } return count;
}function GetDirFilsCount(dirName)
{var dfCount0;$.ajax({url: dskApidirName,type: get,async: true,//true 异步false 同步success: function(data) {var fileLists data.list;dfCountGetFilesCount(fileLists); console.log(decodeURIComponent(dirName)dfCount);console.log(统计目录为“decodeURIComponent(root)” 当前计算总数totalCount 用时 timeSpan(startTime, new Date()));}});return dfCount;
}GetDirFilsCount(root);提示由于百度服务器或者接口可能不稳定会造成查询不准确数据仅供参考。
文件多的话查询比较耗时同步的准确率比异步要高但更耗时。如图用了半个小时才统计了15W左右的数据据百度称俺的文件数超过了500W哈哈。