Subversion Repositories svn.Prod repos

Rev

Rev 37 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #!/usr/bin/env ruby
  2. # =============================================================================
  3. # Create
  4. # name  : Andre Rikkert de Koe          date:   Apr 2011
  5. # descr : filefind
  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
  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.
  10. # run   : interactive
  11. #
  12. # Changes
  13. # name  :                               date:
  14. # descr : short description
  15. #
  16. # =============================================================================
  17.  
  18. # =============================================================================
  19. # Functions
  20. # =============================================================================
  21.  
  22. def Usage(progname, mesg)
  23.         puts "Usage: #{progname} directory"
  24.         puts mesg
  25. end
  26.  
  27. #
  28. # dir is directory to traverse
  29. #
  30. def traverse(dir)
  31.         curdir = Dir.getwd
  32.         Dir.chdir(dir)
  33.         curdir2 = Dir.getwd
  34.         Dir.foreach(Dir.getwd) { | file |
  35.                 pfile = curdir2 + "/" +file
  36.                 if File.directory?(file) && !File.symlink?(file)
  37.                         if (file != "..") && (file != ".")
  38.                                 puts pfile
  39.                                 traverse(file)
  40.                         end
  41.                 else
  42.                         if File.file?(file) || File.symlink?(file)
  43.                                 puts "#{pfile}"
  44.                         else
  45.                                 puts "WARNING: Could not process file $pfile"
  46.                         end
  47.                 end
  48.         }
  49.         Dir.chdir(curdir)
  50. end
  51.  
  52. def start_traverse(directory)
  53.         puts directory
  54.         traverse(directory)
  55. end
  56.  
  57. # =============================================================================
  58. # MAIN
  59. # =============================================================================
  60.  
  61. progname = File.basename($0)
  62. if (ARGV.length == 1)
  63.         directory = ARGV[0]
  64.         if File.directory?(directory)
  65.                 start_traverse(directory)
  66.         else
  67.                 Usage progname, "ERROR: Not a directory #{directory}"
  68.         end
  69. else
  70.         Usage progname, "ERROR: 1 argument expected"
  71. end
  72.