本文作者:kaifamei

清理0字节文件和文件夹

更新时间:2023-08-23 09:58:39 人在看 0条评论

清理0字节文件和文件夹

2023年8月23日发(作者:父母的爱作文500字(精选15篇))

1米8等于几尺几寸-

清理0字节⽂件和⽂件夹  最近突然感觉到个⼈的开发机各种慢,也是啊,从我上⼤学时起⾄今,这台⽼古董跟了我七年多了,还好每年我会亲⼿给它做⼀两次的清理和养护,所以它现在依然可以玩命的为我⼯作。如果我没记错,距离我上⼀次做系统有两年多了,查看了⼀下磁盘的情况,window 2003系统 ,系统盘占了45G(满50G,这个⾥⾯还包括4G的虚拟内存),其他硬盘上也堆积了各种⽂件夹和⽂件,o(︶︿︶)o 唉,删了吧,不舍得,要么是⾃⼰做的,要么是⾟苦弄来的;不删吧,那就是⼀堆杂乱⽆章的垃圾。要怎么办?  给⾃⼰先⽴下这么个规矩 1.⽂件夹深度不能超过5 2.不保留0字节⽂件和⽂件夹 3.执⾏磁盘碎⽚整理(⽂件压缩也是把散碎⽂重组的⼀个好⽅式,然后再解压缩,不懂的就当我是在胡咧咧吧)

究竟这⼏步应该如何快速做到呢?

1.⽂件夹深度不能超过5

cmd 命令有⼀个 tree , 侬晓得伐?C:UsersAdministrator>tree "D:MoontestMoontest删除0⼤⼩⽂件和空⽂件夹" /f⽂件夹 PATH 列表卷序列号为 A043-7C6DD:MOONTESTMOONTEST删除0⼤⼩⽂件和空⽂件夹│ │ 删除0⼤⼩⽂件和空⽂件夹.csproj│├─bin│ ├─Debug│ │ 删除0⼤⼩⽂件和空⽂件夹.exe│ │ 删除0⼤⼩⽂件和空⽂件夹.pdb│ │ 删除0⼤⼩⽂件和空⽂件夹.│ │ 删除0⼤⼩⽂件和空⽂件夹.st│ ││ └─Release├─Controls│ │├─obj│ └─x86│ └─Debug│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ 删除0⼤⼩⽂件和空⽂件夹.│ │ 删除0⼤⼩⽂件和空⽂件夹.exe│ │ 删除0⼤⼩⽂件和空⽂件夹.ces│ ││ └─TempPE│ │└─Properties gsC:UsersAdministrator> 这个层次分明了,如果实在太多,可以输⼊在命令后加上 >> d: 即是tree "D:MoontestMoontest删除0⼤⼩⽂件和空⽂件夹" /f >> d:这种⽅式把结果导出到⼀个⽂件中查看。如果深度太⼤的,可以⼿动处理下,这个尽量不要写代码⾃动化处理,毕竟你不能把你的思维写到计算机⾥⾯,⽂件或删或合并或移位,还是⼈⼯的好点,当然我说的是对⾃⼰有价值有感情的东西,毕竟某些东西视同⼰出。

2.不保留0字节⽂件和⽂件夹  这个不管我们采⽤什么样的系统清理⼯具,清理⼯具考虑系统稳定性,⼀般不会删除不在“花名册”中的0字符⽂件和⽂件夹。这样就可能导致我们曾经在安装删除时,系统中保留了⼤量的卸载后余下的垃圾⽂件(0字符⽂件和⽂件夹),久⽽久之,看到⼀堆堆我不认识的东西,⼼⾥特别不爽,看到⼀个,⼲掉⼀个;但是这种⽅式也太慢了。要怎么办呢?⾃⼰写个清理⽅法吧,呵呵。  我⾃⼰提供⼀下删除0字符⽂件和⽂件夹的⼩代码,⽐较简单,不解释代码了,分成三段,根据喜好索取,我个⼈偏好Class2using System;using c;using ;namespace 删除0⼤⼩⽂件和空⽂件夹{ class Program { /* Class1 和 Class2 的形式是⼀样的,只是删除⽅式不⼀样 Class2 和 Class3 的删除⽅式是⼀样的,只是形式不⼀样 Class1 先检索出所有⽂件夹,从末端⽂件夹开始删除0字节⽂件和⽂件夹 Class2 和 Class3 检查⼀个⽂件夹,先删除0字节⽂件,然后检索⽂件夹,重复以上过程,最后从末端⽂件夹开始删除⽂件夹 */ static void Main(string[] args) { ledException += (s, e) => { AllText(rectory + "", ng() + "t" + ng() + e); }; Class1 c1 = new Class1(args); Class2 c2 = new Class2(args); Class3 c3 = new Class3(args); } } public class Class1 { public Class1(string[] args) { Queue queue = new Queue(); Stack stack = new Stack(); if ( > 0) { foreach (var item in args) { e(item); (item); } } else { string rootPath = rectory; e(rootPath); (rootPath); } while ( > 0) { string curPath = e(); string[] folders = null; try { folders = ectories(curPath); } catch { } if (folders != null && > 0) { foreach (var item in folders) { e(item); (item); } } } while ( > 0) { string curPath = (); string[] files = null; try { files = es(curPath); } catch { } int filecount = 0; if (files != null && > 0) { filecount = ; foreach (var item in files) { FileInfo finfo = new FileInfo(item); if ( <= 0) { try { (); filecount--; ine("delete file : " + me); } catch (Exception ex) { ine(ex); } } } } if (filecount == 0) { try { (curPath); ine("delete folder : " + curPath); } catch (Exception ex) { ine(ex); } } } ine("清理完毕!!!"); y(); } } public class Class2 { public Class2(string[] args) { Queue queue = new Queue(); Stack stack = new Stack(); if ( > 0) { foreach (var item in args) { e(item); (item); } } else { string rootPath = rectory; e(rootPath); (rootPath); } while ( > 0) { string curPath = e(); string[] files = null; try { files = es(curPath); } catch { } if (files != null && > 0) { foreach (var item in files) { FileInfo finfo = new FileInfo(item); if ( <= 0) { try { (); ine("delete file : " + me); } catch (Exception ex) { ine(ex); } } } } string[] folders = null; try { folders = ectories(curPath); } catch { } if (folders != null && > 0) { foreach (var item in folders) { e(item); (item); } } } while ( > 0) { string curPath = (); try { (curPath); ine("delete folder : " + curPath); } catch (Exception ex) { ine(ex); } } ine("清理完毕!!!"); y(); } } public class Class3 { public Class3(string[] args) { if ( == 0) { args = new string[] { rectory }; } foreach (var item in args) Delete(item); ine("清理完毕!!!"); y(); } public void Delete(string path) { string[] files = null; try { files = es(path); } catch { } if (files != null && > 0) { foreach (var item in files) { FileInfo finfo = new FileInfo(item); if ( <= 0) { try { (); ine("delete file : " + me); } catch (Exception ex) { ine(ex); } } } } string[] folders = null; try { folders = ectories(path); } catch { } if (folders != null && > 0) foreach (var item in folders) Delete(item); try { (path); ine("delete folder : " + path); } catch (Exception ex) { ine(ex); } } }}⼩代码

  想⽤拿去编译⼀下就好,想清理哪个磁盘或者⽂件夹,只需把⽣成程序copy过去run就好,当然也可以加参数指定路径。例如写个⽂件,在⾥⾯写⼊call ..这⾥写⽣成程序⽗路径⽣成程序.exe "c:" "D:flash cs6完全⾃学教程" "E:Erlang项⽬" ,然后运⾏下(别怪⼩弟太啰嗦)。

现在话题⼜扯回来了,刚刚我不是还说,很多系统清理⼯具,为了系统的稳定性,不会删除⾮“花名册”中的0字符⽂件和⽂件夹,我现在这么搞,系统稳定性不是⼤受威胁吗?告诉你,如果你⽤的是个⼈计算机,尽管删吧,很多健壮性很好的系统程序都有⽂件⾃恢复能⼒(这⼀点在开发中很重要,配置⽂件被误删,或者是⽆法被程序识别,程序要有⽂件⾃恢复能⼒),不怕啦。但是这种⽅式绝对不允许⽤来清理正在运⾏服务器,除⾮你觉得脖⼦够粗,头掉不下来。

3.执⾏磁盘碎⽚整理  这个就简单了,我喜欢使⽤defraggler,执⾏速度⾮常快,应该和ccleaner出⾃同⼀家族;当然也可以使⽤系统⾃带的磁盘整理⼯具,但是有点偏耗时;如果⽂件⽐较⼤,对连续性要求⽐较⾼的话,可以使⽤压缩⽂件的⽅式。

最终,通过删除、移动、合并⽅式。终于把C盘整理出10G剩余空间,其他盘也做了重复⽂件处理(重复⽂件处理⽐较简单,我这边是读取磁盘所有⽂件,将 ⽂件创建时间和⽂件⼤⼩连接 并 ⽂件路径,作为key-value插⼊哈希表,下次遇到重复键的,对⽐下⽂件特征(当⽂件创建时间和⽂件⼤⼩相等,从两个⽂件中随机取同位符,匹配是否相等,⽤来断定是否同⼀个⽂件),是同⼀个⽂件删除重复)。

什么相照成语四字词语-


文章投稿或转载声明

本文链接:https://www.en369.cn/fanwen/xinxi-1-569041-0.html

来源:范文频道-369作文网版权所有,转载请保留出处。本站文章发布于 2023-08-23 09:58:39

发表评论

验证码:
用户名: 密码: 匿名发表
评论列表 (有 条评论
2人围观
参与讨论