1 import jcifs.smb.SmbFile; 2 import java.util.LinkedList ; 3 import java.util.ListIterator ; 4 import java.net.MalformedURLException ; 5 import java.io.IOException ; 6 7 public class SmbCrawler { 8 9 int maxDepth; 10 11 SmbCrawler( int maxDepth ) { 12 this.maxDepth = maxDepth; 13 } 14 15 void traverse( SmbFile f, int depth ) throws MalformedURLException , IOException { 16 17 if( depth == 0 ) { 18 return; 19 } 20 21 SmbFile[] l = f.listFiles(); 22 23 for(int i = 0; l != null && i < l.length; i++ ) { 24 try { 25 for( int j = maxDepth - depth; j > 0; j-- ) { 26 System.out.print( " " ); 27 } 28 System.out.println( l[i] + " " + l[i].exists() ); 29 if( l[i].isDirectory() ) { 30 traverse( l[i], depth - 1 ); 31 } 32 } catch( IOException ioe ) { 33 System.out.println( l[i] + ":" ); 34 ioe.printStackTrace( System.out ); 35 } 36 } 37 } 38 39 public static void main(String [] argv) throws Exception { 40 int depth = Integer.parseInt( argv[1] ); 41 SmbCrawler sc = new SmbCrawler( depth ); 42 sc.traverse( new SmbFile( argv[0] ), depth ); 43 } 44 } 45 | Popular Tags |