| 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"); |
| } |
| } |