Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ls | 1 | #!/usr/bin/env ruby19 |
2 | # progname : filefind.bash |
||
3 | # purpose : display a directory tree |
||
4 | # similar to find |
||
5 | |||
6 | # ============================================================================= |
||
7 | # Functions |
||
8 | # ============================================================================= |
||
9 | |||
10 | def Usage(progname, mesg) |
||
11 | puts "Usage : #{progname} directory" |
||
12 | puts mesg |
||
13 | end |
||
14 | |||
15 | # |
||
16 | # dir is directory to traverse |
||
17 | # |
||
18 | def traverse(dir) |
||
19 | curdir = Dir.getwd |
||
20 | Dir.chdir(dir) |
||
21 | curdir2 = Dir.getwd |
||
22 | Dir.foreach(Dir.getwd) { | file | |
||
23 | pfile = curdir2 + "/" +file |
||
24 | if File.directory?(file) && !File.symlink?(file) |
||
25 | if (file != "..") && (file != ".") |
||
26 | puts pfile |
||
27 | traverse(file) |
||
28 | end |
||
29 | else |
||
30 | if File.file?(file) || File.symlink?(file) |
||
31 | puts "#{pfile}" |
||
32 | else |
||
33 | puts "WARNING: Could not process file $pfile" |
||
34 | end |
||
35 | end |
||
36 | } |
||
37 | Dir.chdir(curdir) |
||
38 | end |
||
39 | |||
40 | def start_traverse(directory) |
||
41 | puts directory |
||
42 | traverse(directory) |
||
43 | end |
||
44 | |||
45 | # ============================================================================= |
||
46 | # MAIN |
||
47 | # ============================================================================= |
||
48 | |||
49 | progname = File.basename($0) |
||
50 | if (ARGV.length == 1) |
||
51 | directory = ARGV[0] |
||
52 | if File.directory?(directory) |
||
53 | start_traverse(directory) |
||
54 | else |
||
55 | Usage progname, "ERROR: No directory #{directory} found" |
||
56 | end |
||
57 | else |
||
58 | Usage progname, "ERROR: 1 argument expected" |
||
59 | end |