Subversion Repositories svn.Prod repos

Compare Revisions

Ignore whitespace Rev 5 → Rev 6

/filefind/java/filefind.java
0,0 → 1,109
/* ============================================================================
# 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 */
{
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;
}
/**
* 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)
{
String curdir;
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]))
{
System.out.println(subs[i]);
traverse(subs[i]);
}
else
{
System.out.println(subs[i]);
}
}
System.setProperty("user.dir",curdir);
}
 
/* ============================================================================
# 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())
{
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");
}
}
/filefind/java/Makefile.inc
0,0 → 1,21
#
# gmake
# setp PROG variabele in calling file
#
 
.PHONY = clean run
 
$(PROG).class: $(PROG).java
@echo "INFO: Compiling $^ to $@"
javac $^
 
clean:
@echo "INFO: Cleaning $(PROG)"
rm -f $(PROG).class
 
run: $(PROG).class
@echo "INFO: Running $(PROG)"
java $(PROG)
 
all:
echo "$(PROG)"
/filefind/java/Makefile
0,0 → 1,21
 
# http://users.erols.com/ziring/java-src/FileWalk.java
 
PROG = filefind
 
include Makefile.inc
 
DIR = /home/arikkert
 
test: $(PROG).class
java $(PROG) $(DIR) > result
sort result > result.sort
find $(DIR) > result2
sort result2 > result2.sort
wc *.sort
diff *.sort
 
clean2:
rm -f filefind
rm -rf result result.sort
rm -rf result2 result2.sort