Rev 43 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 43 | Rev 44 | ||
---|---|---|---|
1 | #!/usr/bin/env ruby |
1 | #!/usr/bin/env ruby |
2 | # ============================================================================= |
2 | # ============================================================================= |
3 | # Create |
3 | # Create |
4 | # name : Andre Rikkert de Koe date: Apr 2011 |
4 | # name : Andre Rikkert de Koe date: Apr 2011 |
5 | # descr : filefind |
5 | # descr : filefind |
6 | # This is a demo of programming in the ruby language. |
6 | # This is a demo of programming in the Ruby language. |
7 | # Its part of a project to implement a program to create a directory |
7 | # Its part of a project to implement a program to create a directory |
8 | # tree similar to the output of the Unix find program. |
8 | # tree similar to the output of the Unix find program. |
9 | # EUID : Any user who has read access to all the files being searched for. |
9 | # EUID : Any user who has read access to all the files being searched for. |
10 | # run : interactive |
10 | # run : interactive |
11 | # |
11 | # |
12 | # Changes |
12 | # Changes |
13 | # name : date: |
13 | # name : date: |
14 | # descr : short description |
14 | # descr : short description |
15 | # |
15 | # |
16 | # ============================================================================= |
16 | # ============================================================================= |
17 | 17 | ||
18 | # ============================================================================= |
18 | # ============================================================================= |
19 | # Functions |
19 | # Functions |
20 | # ============================================================================= |
20 | # ============================================================================= |
21 | 21 | ||
22 | def Usage(progname, mesg) |
22 | def Usage(progname, mesg) |
23 | puts "Usage: #{progname} directory" |
23 | puts "Usage: #{progname} directory" |
24 | puts mesg |
24 | puts mesg |
25 | end |
25 | end |
26 | 26 | ||
27 | # |
27 | # |
28 | # dir is directory to traverse |
28 | # dir is directory to traverse |
29 | # |
29 | # |
30 | def traverse(dir) |
30 | def traverse(dir) |
31 | curdir = Dir.getwd |
31 | curdir = Dir.getwd |
32 | Dir.chdir(dir) |
32 | Dir.chdir(dir) |
33 | curdir2 = Dir.getwd |
33 | curdir2 = Dir.getwd |
34 | Dir.foreach(Dir.getwd) { | file | |
34 | Dir.foreach(Dir.getwd) { | file | |
35 | pfile = curdir2 + "/" +file |
35 | pfile = curdir2 + "/" +file |
36 | if File.directory?(file) && !File.symlink?(file) |
36 | if File.directory?(file) && !File.symlink?(file) |
37 | if (file != "..") && (file != ".") |
37 | if (file != "..") && (file != ".") |
38 | puts pfile |
38 | puts pfile |
39 | traverse(file) |
39 | traverse(file) |
40 | end |
40 | end |
41 | else |
41 | else |
42 | if File.file?(file) || File.symlink?(file) |
42 | if File.file?(file) || File.symlink?(file) |
43 | puts "#{pfile}" |
43 | puts "#{pfile}" |
44 | else |
44 | else |
45 | puts "WARNING: Could not process file $pfile" |
45 | puts "WARNING: Could not process file $pfile" |
46 | end |
46 | end |
47 | end |
47 | end |
48 | } |
48 | } |
49 | Dir.chdir(curdir) |
49 | Dir.chdir(curdir) |
50 | end |
50 | end |
51 | 51 | ||
52 | def start_traverse(directory) |
52 | def start_traverse(directory) |
53 | puts directory |
53 | puts directory |
54 | traverse(directory) |
54 | traverse(directory) |
55 | end |
55 | end |
56 | 56 | ||
57 | # ============================================================================= |
57 | # ============================================================================= |
58 | # MAIN |
58 | # MAIN |
59 | # ============================================================================= |
59 | # ============================================================================= |
60 | 60 | ||
61 | progname = File.basename($0) |
61 | progname = File.basename($0) |
62 | if (ARGV.length == 1) |
62 | if (ARGV.length == 1) |
63 | directory = ARGV[0] |
63 | directory = ARGV[0] |
64 | if File.directory?(directory) |
64 | if File.directory?(directory) |
65 | start_traverse(directory) |
65 | start_traverse(directory) |
66 | else |
66 | else |
67 | Usage progname, "ERROR: Not a directory #{directory}" |
67 | Usage progname, "ERROR: Not a directory #{directory}" |
68 | end |
68 | end |
69 | else |
69 | else |
70 | Usage progname, "ERROR: 1 argument expected" |
70 | Usage progname, "ERROR: 1 argument expected" |
71 | end |
71 | end |
72 | 72 |