//List <File> directoryList is used to save all directories. private List <File> directoryList = new ArrayList <File> ();
//List <File> fileList is used to save all files. private List <File> fileList = new ArrayList <File> ();
/** * @return the list of all directories in the directory. * */ public List <File> getDirectoryList() { return directoryList; }
/** * @return the list of all files in the directory. * */ public List <File> getFileList() { return fileList; }
/** * If the File appointed is file, * then print its attributes. * * If the File appointed is directory, * then traverse the appointed, * add all directories and files in the directory to their own list. * * @param name the name of the file or path. * */ public void loadFile(String name) { //isBeginning用于标记是否是第一次循环 boolean isBeginning = true; File file = new File(name);
if (file.isDirectory()) { for (int i = 0; i <directoryList.size() ||isBeginning; ){ //第一次循环时directoryList为空 File[] files = file.listFiles();
if (isBeginning){ //第一次循环是遍历根目录,i不自加。 isBeginning = false; //第一次循环结束 }
if (directoryList.size() > 0){ file = directoryList.get(i); i++; }
//main方法 public static void main(String[] args) { long startTimeMillis = System.currentTimeMillis(); long endTimeMillis; FileTool test = new FileTool();
@echo off if not "%1 "== " " (cd "%1 " & goto a); set deldir=f:\zheng\delete\ copy d.bat %deldir%d.bat cd /d %deldir% :a dir /ad /b> dir.txt for /f "tokens=1 " %%i in (dir.txt) do (copy d.bat %%i\ & call %%i\d %%i) dir /a ::for /f "tokens=1 " %%i in (dir.txt) do rmdir %%i ::del /f /q /a *.*&cd..