當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
利用JS脚本快速删除百度网盘同一目录下的不需要文件(可以参考这个方法删除重复文件)
生活随笔
收集整理的這篇文章主要介紹了
利用JS脚本快速删除百度网盘同一目录下的不需要文件(可以参考这个方法删除重复文件)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
比如百度網盤某目錄下存有如下文件:
要求:將如上圖文件目錄下的文件,每個月只保留最后(新)一個(根據文件名中包含的日期),其它刪除。
比如7月份有3個文件,只保留2019-07-21那天的文件,刪除7月份的其它2個。
?
代碼實現步驟:
1、獲取當前目錄名稱:“CZSX030A”
2、遍歷獲取每個文件名中包含的日期,如“CZSX030A_20190721000002.bak”-->"201907"
3、模擬點擊事件,選中每個月份中除了第一個文件
var temptime = "",sltCount = 0; var currentPath= $(".FuIxtL li:last-child span:last-child").attr("title"); var tag = currentPath.substring(currentPath.lastIndexOf('/')+1);//當前目錄名稱 $("dd").each(function() {var tt =$(this).find(".file-name>.text").text().replace(tag+"_","").replace("-", "").substring(0, 6);//截取文件名中的日期//var temptag =$(this).find(".file-name>.text").text().replace(tag+"_","").replace("-", "").substring(1, 9); if (tt != "" && !isNaN(tt)) {if (tt != temptime) {temptime = tt;} else {$(this).find(".NbKJexb").trigger('click');//選擇日期相同且非第一個的記錄sltCount++;}console.log(tt);} });console.clear(); console.log(tag + " 共選擇了"+sltCount+"條數據");?
4、模擬點擊“刪除”按鈕
?
$("a[title='刪除']:visible").trigger('click');5、模擬點擊彈出提示層“確認”按鈕
?
$(".g-button-blue-large").trigger('click');6、等刪除完成
?
7、執行結果
?附:完整代碼
本文代碼的功能是根據月份清理文件,當然可以修改條件代碼,執行您想執行的操作,比如可以刪除目錄下的重復文件等。
/** *清理網盤文件JS代碼 *Jackie *2019.07.10 **/ var temptime = "",sltCount = 0; var currentPath= $(".FuIxtL li:last-child span:last-child").attr("title"); var tag = currentPath.substring(currentPath.lastIndexOf('/')+1);//當前目錄名稱 $("dd").each(function() {var tt =$(this).find(".file-name>.text").text().replace(tag+"_","").replace("-", "").substring(0, 6);//截取文件名中的日期//var temptag =$(this).find(".file-name>.text").text().replace(tag+"_","").replace("-", "").substring(1, 9); if (tt != "" && !isNaN(tt)) {if (tt != temptime) {temptime = tt;} else {$(this).find(".NbKJexb").trigger('click');//選擇日期相同且非第一個的記錄sltCount++;}console.log(tt);} });console.clear(); console.log(tag + " 共選擇了"+sltCount+"條數據"); if(sltCount>0) {setTimeout(function(){console.log("執行刪除!");$("a[title='刪除']:visible").trigger('click');setTimeout(function(){console.log("確認刪除!");$(".g-button-blue-large").trigger('click');},1000);},1000); } else {console.log("無可刪除記錄!"); } //返回 setTimeout(function(){window.history.back(-1); },2000); //自動定位到上次操作目錄,便于處理下一目錄 var currentDD; var container=$('.NHcGw'); $("dd").each(function() {if($(this).find("a:eq(0)").text()==tag){currentDD=$(this); } });if(currentDD) {if(currentDD.offset().top>container.offset().top){currentDD.css("background-color","yellow");//自動定位到上次操作目錄container.animate({scrollTop: currentDD.offset().top-container.offset().top + "px"},500);}//自動打開下一目錄currentDD.next().find("a:eq(0)").trigger('click'); } console.clear();?
總結
以上是生活随笔為你收集整理的利用JS脚本快速删除百度网盘同一目录下的不需要文件(可以参考这个方法删除重复文件)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [转]总结:Apache/Tomcat/
- 下一篇: [转]Angular 单元测试讲解