/ ** * /
/ ** * Author: Yang Fan * mail: yifi@tom.com * licence: GPL or revise forward Keep the original author information * /
Import
Java.io.
*
;
Import
Java.util.
*
;
public
Class
Mytree
...
{Public static void main (string [] args) ... {Madetree MT = new Madetree (); try ... {file file = new file (args [0]); if (file.Isdirectory () == false ) ... {throw new exception ("Not a directory!");} Mt.made (file, 0, new linkedlist ());} catch (exception e) ... {system.out.println ("Usage: Java mytree directory name "); E.PrintStackTrace ();}}}
Class
Madetree
...
{Public static String signTreeBranch = "├─"; public static String signTreeLastBranch = "└─"; public static String signTreeThroughBranch = "│"; public static String signTreeNoneBranch = ""; public static boolean isPrintFile = true; // true: Show File False: Do not display file public void name (file file, int num, linkedlist link) ... {file [] fileRay; if (Madetree.IsprintFile == true) ... {fileRay = file.listfiles (); Else ... {fileRay = file.listfiles (new myfilefilter ());} iter = link.Itemrator (); whil (it.hasnext ()) ... {system.out.print (it.next () );} If (fileRay == null) ... {// Description passed the empty directory or file system.out.println (file.getname ());} else ... {// Description passed It is a directory with content system.out.println ("[" file.getname () "]"); // Handling the next directory IF (Link! = Null && link.size ()> 0) .. . {// If the parent node is branch, use SIGNTRE Ethroughbranch instead of IF (Link.GetLast (). Equals (Madetree.Signtreebranch) ... {link.removelast (); link.addlast (Madetree.SigntreethRoughbranch);} // If the parent node is the end of the end, use SignTreennebranch instead of IF (Link.getlast (). Equals (Madetree.SigntreeLastbranch) ... {link.removelast (); link.addlast (Madetree.signTreenBranch);}}}}}}}}}}}}}}} link.addlast (Madetree.signTreebranch); for (INT i = 0 I FileArray.Length - 1) ... {// Processing a branch} else ... {// Processing the end LINK.RemoveLast (); link.addlast (Madetree.SignTreeLastBranch);} // should pay special attention to Link is to Clone, or you don't share a Made (FileArray [i], Num 1, (LinkedList) link.clone ());}}}} / ** * / / ** * File filter, filter out is not a directory file * / Class Myfilefilter IMPLEMENTS FILEFILTER ... {Public Boolean Accept (File Pathname) ... {if (Pathname.IsDirectory ()) ... {Return True;} else ... {Return False;}}}