zoukankan      html  css  js  c++  java
  • import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.FileFilter;
    public class Folder{
    private static FolderFilter folderFilter;
    private static FilesFilter filesFilter;
    public static void main(String[] args){
    folderFilter=new FolderFilter();
    filesFilter=new FilesFilter();
    switch(args.length){
          case 0:tree(".");break;
          case 1:tree(args[0]);break;
          case 2:
              if(args[0].toLowerCase().equals("add")){
                  //添加新文件夹
              }
              else if(args[0].toLowerCase().equals("del")){
                  //删除文件夹
              }
              tree(".");
              break;
    }
    }
    public static void tree(String path){
         try{
            System.out.println(new File(path).getCanonicalPath());
               doTree(new File(path),"");
            }
            catch(IOException ex){
                ex.printStackTrace();
            }
    }
    private static void doTree(File parent,String prefix){
    File[] subItems=parent.listFiles(folderFilter);
    int count=parent.listFiles().length;
    for(int i=0;i<subItems.length;i++){
          if(i==count-1){
           System.out.println(prefix+"└"+subItems[i].getName());
           doTree(subItems[i],prefix.concat(" "));
          }
          else{
           System.out.println(prefix+"├"+subItems[i].getName());
           doTree(subItems[i],prefix.concat("│"));
          }
    }
    subItems=parent.listFiles(filesFilter);
    for(int i=0;i<subItems.length;i++){
          if(i==subItems.length-1){
           System.out.println(prefix+"└"+subItems[i].getName());
          }
          else{
           System.out.println(prefix+"├"+subItems[i].getName());
          }
    }
    }
    }
    class FolderFilter implements FileFilter{
    public boolean accept(File file){
    return file.isDirectory();
    }
    }
    class FilesFilter implements FileFilter{
    public boolean accept(File file){
    return file.isFile();
    }
    }

  • 相关阅读:
    八款常用的 Python GUI 开发框架推荐
    scrapy + mogoDB 网站爬虫
    tkinter界面卡死的解决办法
    通过核心API启动单个或多个scrapy爬虫
    爬虫怎样绕过验证码?
    Python爬虫入门教程 33-100 电影评论数据抓取 scrapy
    Python开发 之 Websocket 的使用示例
    StringBuffer详解
    其实python正则表达式就这样简单明了
    ABAP和Java里的单例模式攻击
  • 原文地址:https://www.cnblogs.com/frostbelt/p/1763312.html
Copyright © 2011-2022 走看看