Rev 10 | Rev 37 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/* ============================================================================
# Create
# name : Andre Rikkert de Koe date: apr 2011
# descr : filefind
# This is a demo of programming in the java language.
# Its part of a project to implement a program to create a directory
# tree similar to the output of the Unix find program.
# EUID : Any user who has read access to all the files being searched for.
# run : interactive
#
# Changes
# name : date:
# descr : short description
#
# ========================================================================== */
import java.io.*;
import java.util.*;
public class filefind
{
protected File base;
protected PrintStream out;
static void Usage(String progname, String mesg)
{
System.out.println("Usage: " + progname + " directory");
System.out.println(mesg);
}
static boolean issymlink(File file1)
{
boolean result;
try
{
result = !file1.getAbsolutePath().equals(file1.getCanonicalPath());
}
catch (IOException ie)
{
System.err.println("Caught IOException: " + ie.getMessage());
result = false;
}
return result;
}
public filefind(String filename)
{
base = new File(filename);
}
static void start_traverse(File base)
{
try
{
System.out.println(base.getCanonicalPath());
}
catch (IOException ie)
{
System.err.println("Caught IOException: " + ie.getMessage());
}
traverse(base);
}
static void traverse(File b)
{
File [] subs = b.listFiles();
for(int i = 0; i < subs.length; i++)
{
if (subs[i].isDirectory() && !issymlink(subs[i]))
{
System.out.println(subs[i]);
traverse(subs[i]);
}
else
{
System.out.println(subs[i]);
}
}
}
/* ============================================================================
# MAIN
# ========================================================================== */
public static void main(String [] args)
{
String basename;
String progname = "filefind";
if (args.length == 1)
{
basename = args[0];
File base = new File(basename);
if (base.isDirectory())
{
start_traverse(base);
}
else
{
Usage(progname, "ERROR: No directory " + basename + " found");
}
}
else
Usage(progname, "ERROR: 1 argument expected");
}
}