// MakeCopyList.java
//
// You may use and distribute this example. This program is 
// provided WITHOUT WARRANTY either expressed or implied.
//
// Copyright Henrik Björkman 1998
//
// Description: See usage below.
//
// History:
// 0.0 Created by Henrik Björkman 1998-06-09 
//


import java.io.*;



public class MakeCopyList
{

  static void error(String str)
  {
    System.err.println("MakeCopyList: " + str);
  }

  static void debug(String str)
  {
    //error(str);
  }

  static void print(String str)
  {
    System.out.println(str);
  }

  static void show_file(String root1, String root2, String name, int depth)
  {
    File f1,f2;

    debug(root1+" "+root2+" "+name+" "+depth);

    f1=new File(root1+name);
    if (f1.isDirectory())
    { 
      int i;
      String[] n;
      //print(name+'/');
      n=f1.list();
      for (i=0;i<n.length;i++)
      {
        show_file(root1,root2,name+"/"+n[i],depth+1);
     }
    }
    else if (f1.isFile())
    {
      f2=new File(root2+name);        
      /* kolla om f2 inte finns eller är äldre */
      if ((!f2.exists()) || (!f2.isFile()) || (f2.lastModified()!=f1.lastModified()))
      {
        print(f1.getAbsolutePath()+" "+f2.getAbsolutePath());
      }
    }
    else
    {
      print(root1+name+" ?");
    }
  }

  public static void main(String args[]) 
  {
    debug("begin");

    if (args.length < 2 )
    {
      print("");
      print("Usage: java MakeCopyList <dir1> <dir2>");
      print("");
      print("List all files in <dir1> that don't exist in <dir2> or have a");
      print("different modification time there. ");
      print("");
      print("Buggs: On dos giving just <drive letter>: don't work.");
      print("");
      System.exit(0);
    }

    show_file(args[0],args[1],"",0);

    debug("end");
  }
}


