// MergeFilesInDir.java
//
// You may use and distribute this example. This program is 
// provided WITHOUT WARRANTY either expressed or implied.
//
// Copyright Henrik Björkman 1998
//
//
// This program will dump the contens of all files in a directory 
// to stdout.
//
//
// History:
// 0.0 Created by Henrik Björkman 1998-02-28 
//     (using code from H4Replace.java)
//


import java.io.*;



public class MergeFilesInDir
{

  static void error(String str)
  {
    System.err.println("MergeFilesInDir: " + str);
    System.exit(-1);
  }

  static void debug(String str)
  {
    //error(str);
  }

  static void print(String str)
  {
    System.out.println(str);
  }

  static void type_file(String name)
  {
    print(name);

    try 
    {
      FileInputStream in=new FileInputStream(name);

      for(;;) 
      {
        int ch = in.read();
        if (ch<0) break;
        System.out.print((char)ch);
      }

      in.close();
    }
    catch (IOException e) {error("run: " + e);}

    print("");

  }

  static void show_file(String name,int depth)
  {
    File f;
    f=new File(name);
    if (f.isDirectory())
    { 
      int i;
      String[] n;
      //print(name+'/');
      n=f.list();
      for (i=0;i<n.length;i++)
      {
        show_file(name+"/"+n[i],depth+1);
      }
    }
    else if (f.isFile())
    {
      type_file(name);
    }
    else
    {
      print(name+" ?");
    }
  }


  public static void main(String args[]) 
  {
    debug("begin");

    if (args.length < 1 )
    {
      System.out.println("Usage: java MergeFilesInDir <name>");
      System.exit(0);
    }

    show_file(args[0],0);

    debug("end");
  }
}


