source: rubysleuth/ntfsdirrec @ 277

Revision 277, 936 bytes checked in by henning, 16 months ago (diff)

rubysleuth: test on tools in PATH, recover() as block method

  • Property svn:executable set to *
Line 
1#!/usr/bin/env ruby
2
3require 'sleuth.rb'
4include Sleuth
5
6if ARGV.count != 2
7        $stderr.print( "Usage: #{File.basename( $0 )} <image> <pattern>\n" )
8        exit( 1 )
9else
10        haystack = ARGV[0]
11        needle = ARGV[1]
12end
13
14begin
15#       throw Exception if not File.stat( haystack ).readable?
16rescue
17        $stderr.print( "'#{haystack}' could not be found or is unreadable.\n" )
18        exit( 1 )
19end
20
21print( "Searching for '#{needle}' in '#{haystack}'..\n\n" )
22
23matches = Image.new( haystack ).searchDir( needle )
24if matches.count > 0
25        print( "Found #{matches.count} matches:\n" )
26
27        i = 0
28        matches.each do |match|
29                i += 1
30                print( #{i}. #{match}\n" )
31        end
32
33        choice = 0
34        while choice < 1 or choice > i
35                print( "\nChoose wisely (by number): " )
36                begin
37                        choice = $stdin.gets.to_i
38                rescue Interrupt
39                        exit( 1 )
40                end
41        end
42       
43        choice -= 1
44        matches[choice].recover do |match|
45                print( "#{match.path}\n" )
46        end
47else
48        $stderr.print( "No matches found.\n" )
49        exit( 1 )
50end
Note: See TracBrowser for help on using the repository browser.