// ListDiffMod.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 ListDiffMod
{

  static void error(String str)
  {
    System.err.println("ListDiffMod: " + 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;

    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("copy "+f1.getAbsolutePath()+" "+f2.getAbsolutePath());
      }
    }
    else
    {
      print(name+" ?");
    }
  }

  public static void main(String args[]) 
  {
    debug("begin");

    if (args.length < 2 )
    {
      System.out.println("Usage: java ListDiffMod <dir1> <dir2>");
      System.out.println("List all files in dir1 that don't exist in dir2 or have a different modification time there.");
      System.exit(0);
    }

    show_file(args[0],args[1],"",0);

    debug("end");
  }
}


