杀杀杀

阅读更多
这两天公司闹蠕虫,会在每个目录里放一个_desktop.ini文件。杀毒软件可以杀掉病毒,但是不会清除文件。今天自己机器也感染了,写了个小工具做这个清除工作,竟然删掉了十一万个残留文件 。代码如下:
import java.io.File;
import java.io.FileFilter;

public class FileCleaner {
	//file name to be deleted
	private String fileName = null;
	//deleted file number counter
	private int counter = 0;
	
	public FileCleaner(String fileName){
		if(fileName == null || fileName.length() <= 0)
			throw new IllegalArgumentException();
		
		this.fileName = fileName;
	}
	
	/**
	 * entry method
	 * 
	 * @param path directory to be processed
	 */
	public void cleanFile(String path){
		File dir = new File(path);
		
		if(!dir.isDirectory())
			return;
		
		processDir(dir);
	}
	
	/**
	 * returns the deleted file number
	 * 
	 * @return
	 */
	public int getDeletedFileCount(){
		return counter;
	}

	private void processDir(File tmp) {
		System.out.println("Start to check " + tmp.getAbsolutePath());
		File[] acceptedFiles = tmp.listFiles(new FileFilter(){
			public boolean accept(File f){
				if(f.isDirectory() || fileName.equals(f.getName()))
					return true;
				else
					return false;
			}
		});
		
		if(acceptedFiles != null && acceptedFiles.length > 0){
			for(int n=0;n 

你可能感兴趣的:(Ruby,F#,C,C++,C#)