import java.io.*;
import java.net.*;

/***
 * Shows all the files in a directory tree above a certain size.
 * Example of working with files and directories in java
 * send comments and corrections to mitch[at]fincher[dot]org
 * example to show all files on your c drive above one meg:
 *            java ListFiles c: 1000000
 * @author mitch fincher 
 *
**/
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
public class ListFiles
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
{
  static int MAX_COLS = 13;
  static int MinSize = 1000;
  
/***
 * describes a file's size.  If the file is a directory it recurses.
 * @param myfile the current file being examined.
**/
////////////////////////////////////////////////////////////////
static public void describeFile(File myfile)
////////////////////////////////////////////////////////////////
  {

    if(myfile.isDirectory())
      {
	String[] files = myfile.list();
	for(int i=0;i<files.length;i++)
	  {
	    describeFile(new File(myfile.getAbsolutePath()+"/"+files[i]));
	  }
      }
    else
      {
	if(myfile.length() < ListFiles.MinSize)return;
	
	String sizeString = ""+myfile.length();
	while(sizeString.length() < MAX_COLS ) // gotta be a better way to justify
	  sizeString = " " + sizeString;
	System.out.println(sizeString + "   " + myfile.getPath());
      }
  }

////////////////////////////////////////////////////////////////
public static void  main(String argv[])
////////////////////////////////////////////////////////////////
  {
    String dir = "c:";
    if(argv.length == 0)
      {
	System.out.println("\nusage: ListFiles directory [min_size]" );
	System.out.println("   this shows all the files in a directory and below over a specified size." );
	System.out.println("   example: ListFiles c: 1000" );
	System.exit(1);
      }

    if(argv.length > 0)
      dir = argv[0];
    if(argv.length > 1)
      ListFiles.MinSize = Integer.parseInt(argv[1]);

    File topfile = new File(dir);
    describeFile(topfile);
  }


}


