Subversion Repositories svn.Prod repos

Rev

Rev 6 | Rev 11 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 ls 1
/* ============================================================================
2
# Create
3
# name  : Andre Rikkert de Koe          date:   apr 2011
4
# descr : filefind
5
#         This is a demo of programming in the java language.
6
#         Its part of a project to implement a program to create a directory
7
#         tree similar to the output of the Unix find program.
8
# EUID  : Any user who has read access to all the files being searched for.
9
# run   : interactive
10
#
11
# Changes
12
# name  :                               date:
13
# descr : short description
14
#
15
# ========================================================================== */
16
 
17
import java.io.*;
18
import java.util.*;
19
 
10 ls 20
public class filefind
6 ls 21
{
22
	protected File base;
23
	protected PrintStream out;
24
 
25
	static void Usage(String progname, String mesg)
26
	{
27
		System.out.println("Usage: " + progname + " directory");
28
		System.out.println(mesg);
29
	}
30
 
31
	static boolean issymlink(File file1)
32
	{
33
		boolean result;
34
		try
35
		{
36
			result = !file1.getAbsolutePath().equals(file1.getCanonicalPath());
37
		}
38
		catch (IOException ie)
39
		{
40
			System.err.println("Caught IOException: " + ie.getMessage());
41
			result = false;
42
		}
43
		return result;
44
	}
10 ls 45
 
6 ls 46
	public filefind(String filename)
47
	{
48
        	base = new File(filename);
49
	}
50
 
10 ls 51
	static void start_traverse(File base, String basename)
6 ls 52
	{
10 ls 53
		System.out.println(basename);
6 ls 54
		traverse(base);
55
	}
56
 
57
	static void traverse(File b)
58
    	{
59
		File [] subs = b.listFiles();
60
		for(int i = 0; i < subs.length; i++)
61
		{
62
			if (subs[i].isDirectory() && !issymlink(subs[i]))
63
			{
64
				System.out.println(subs[i]);
65
				traverse(subs[i]);
66
			}
67
			else
68
			{
69
				System.out.println(subs[i]);
70
			}
71
		}
72
	}
73
 
74
/* ============================================================================
75
# MAIN
76
# ========================================================================== */
77
 
78
	public static void main(String [] args)
79
	{ 
80
        	String basename;
81
		String progname = "filefind"; 
82
        	if (args.length == 1)
83
		{
84
			basename = args[0];
85
			File base = new File(basename);
86
			if (base.isDirectory())
87
			{
10 ls 88
				start_traverse(base, basename);
6 ls 89
			}
90
			else
91
			{
92
	   			Usage(progname, "ERROR: No directory " + basename + " found");
93
			}
94
		}
95
		else
96
	   	Usage(progname, "ERROR: 1 argument expected");
97
    	}
98
}