/* ============================================================================
# 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 /*implements Runnable */
{
{
System.
out.
println("Usage: " + progname +
" directory");
}
static boolean issymlink
(File file1
)
{
boolean result;
try
{
result = !file1.getAbsolutePath().equals(file1.getCanonicalPath());
}
{
System.
err.
println("Caught IOException: " + ie.
getMessage());
result = false;
}
return result;
}
/**
* Create a filefind object for the given string, with
* a print indentation given.
*/
public filefind
(String filename
)
{
base =
new File(filename
);
}
public void start_traverse
(String directory
)
{
System.
out.
println(directory
);
traverse(base);
}
static void traverse
(File b
)
{
curdir = b.getAbsolutePath();
System.
setProperty("user.dir",curdir
);
File [] subs = b.
listFiles();
for(int i = 0; i < subs.length; i++)
{
//File f2 = new File(subs[i]);
if (subs[i].isDirectory() && !issymlink(subs[i]))
{
traverse(subs[i]);
}
else
{
}
}
System.
setProperty("user.dir",curdir
);
}
/* ============================================================================
# MAIN
# ========================================================================== */
public static void main
(String [] args
)
{
if (args.length == 1)
{
basename = args[0];
if (base.isDirectory())
{
filefind walker = new filefind(basename);
//walker.setOutput(System.out);
walker.start_traverse(basename);
}
else
{
Usage(progname, "ERROR: No directory " + basename + " found");
}
}
else
Usage(progname, "ERROR: 1 argument expected");
}
}