删除垃圾文件

admin2021-05-10  195

//清理垃圾
var clean=function(mainForm){//如果在线程中,需要加mainForm,fsys两个参数
	import fsys;
    //var userPath=win.getenv("USERPROFILE");
	fsys.enum( "c:\", {"*.tmp";"*.old";"*.chk";"*._mp";"*.log";"*.gid";"*.xlk";"*.bak"},  
    	function(dir,filename,fullpath,findData){
        	if(fullpath){
        		fsys.attrib(fullpath,0x20/*_FILE_ATTRIBUTE_ARCHIVE*/);
            	if(io.remove(fullpath)){
            		mainForm.richedit.print("删除文件:"+fullpath+" 成功");
            	}else{
            		mainForm.richedit.print("删除文件:"+fullpath+" fail");
            	}
            	
            	//io.print("删除文件1:"+fullpath)/*可使用 return false退出枚举文件过程*/  
        	}
	
    	}   
    	,true
	);
    
    var userPath=fsys.getParentDir(fsys.getSpecialDefault());
	var winDir=fsys.getWinDir();
	var path2={userPath+"\cookies\";userPath+"\recent\";winDir+"\temp\";userPath+"\local settings\temp\";
	userPath+"\local settings\temporary internet files\";winDir+"\Prefetch\";userPath+"\AppData\Local\Temp\";
	userPath+"\AppData\Local\Microsoft\Windows\Caches\";userPath+"\AppData\Local\Microsoft\Windows\INetCache\"}
	for k,v in path2{
		//mainForm.richedit.print(v);
		try{

			fsys.enum(v, "*.*",
    			function(dir,filename,fullpath,findData){
        			if(fullpath){
        				fsys.attrib(fullpath,0x20/*_FILE_ATTRIBUTE_ARCHIVE*/);
        				if(io.remove(fullpath)){
        					mainForm.richedit.print("删除文件:"+fullpath+"成功");
        				}else{
        					mainForm.richedit.print("删除文件:"+fullpath+"失败");
        				}
            			//io.print("删除文件2:"+fullpath)/*可使用 return false退出枚举文件过程*/  
        			}  
		
    			}   
    			,true
			);
		}
		
	
	}
	
	//清空回收站,调用winapi接口
	::Shell = raw.loadDll("Shell32.dll")
	SHEmptyRecycleBin = Shell.api("SHEmptyRecycleBin","addr(addr hwnd,string rootPath,INT flags)" )

	var emptyRecycleBin = function(hwnd=0,rootPath,flags=1){
    	return 0 == SHEmptyRecycleBin(hwnd,rootPath,flags);
	}
	emptyRecycleBin();
	mainForm.richedit.print("清空回收站");
	
}

clean();
转载请注明原文地址: https://seopai.com/read-179.html
最新回复(0)