java文件遍利

来源:互联网 发布:preg replace php手册 编辑:程序博客网 时间:2024/04/27 20:25
/*
 * 作成日: 2006/04/13
 *
 * TODO この生成されたファイルのテンプレートを変更するには次へジャンプ:
 * ウィンドウ - 設定 - Java - コード・スタイル - コード・テンプレート
 */
package ANGO.GM0003;
import java.io.*;
/**
 * @author Border
 *
 * TODO この生成された型コメントのテンプレートを変更するには次へジャンプ:
 * ウィンドウ - 設定 - Java - コード・スタイル - コード・テンプレート
 */
public class ListFile {
 
 public int folderCount;
 public int fileCount;
 public String oldPath;
 public String path;
 public String allFolderStr = "";
 public String allFileStr = "";
 public String splite = "____";
 
 public void listFile(File file) throws Exception {
  if(file.isFile()) {
   path = file.getParent();     //get file path
   allFolderStr = allFolderStr + splite + "/r/n" + path;   // all folder String
   
   //System.out.println(" oldPath "  + oldPath);
   //System.out.println(" path    "  + path);
   
   if(!path.equals(oldPath)){    // the folder count
    folderCount++;
    //System.out.println("folderCount " + folderCount);
   }
   oldPath = path;
   String str = file.getAbsolutePath();     //get file path and name
   allFileStr = allFileStr + splite + "/r/n" +str ;   //all file String
   fileCount++;   // the file count
   //System.out.println("File :"+ str);
   
  
   
   
  } else {
   // System.out.println("Dir :"+file.getAbsolutePath());
   
   File[] files = file.listFiles();  
   for(int i = 0;i<files.length;i++) {
    
     listFile(files[i]);
    }
   }
  
  }
 
  
 public static void main(String[] args) throws Exception{
  ListFile list = new ListFile();
  list.listFile(new File("D://server01"));
  System.out.println("    folderCount   " + list.folderCount);
  System.out.println("    fileCount   " + list.fileCount);
  System.out.println("    allFolderStr /r/n"  + list.allFolderStr);
  System.out.println("    allFileStr   /r/n"  + list.allFileStr);
 }
 
 
}