7575
7676# See if we have a directory to work on
7777if ($input_directory ) {
78+
79+ # Make directory absolute
80+ $input_directory = File::Spec-> rel2abs($input_directory );
81+
82+ # Check to make sure the directory exists
7883 if (! -d $input_directory ) {
7984 die " Directory $input_directory does not exist\n " ;
8085 }
8186
8287 # Tell the user what we're doing
8388 print " Search Directory: $input_directory \n " ;
8489
85- $output_directory = create_run_output_directory($output_directory , " folder" , 1);
90+ # Capture the lowest level folder name for the output directory
91+ my $tmp_folder_name = " folder_search" ;
92+ if ($input_directory =~ / ([^\\\/ ]+)$ / ) {
93+ $tmp_folder_name = $1 ;
94+ }
8695
96+ $output_directory = create_run_output_directory($output_directory , $tmp_folder_name , 1);
8797 $results_file = create_results_file($output_directory );
8898
8999 # Pull out all potential SQLite files (based on file itself)
@@ -161,7 +171,7 @@ sub create_results_file {
161171 # Create the output file and spit the head to it
162172 my $output_file = File::Spec-> catfile($run_folder , " results.csv" );
163173 open (RESULT_OUTPUT, " >$output_file " ) or die " Can't open $output_file to write results\n " ;
164- print RESULT_OUTPUT " \" Database\" ,\" Table\" ,\" Column\" ,\" Primary Key Column\" ,\" Index\" ,\" File Type\" " ;
174+ print RESULT_OUTPUT " \" Directory \" , \" Database\" ,\" Table\" ,\" Column\" ,\" Primary Key Column\" ,\" Index\" ,\" File Type\" " ;
165175 if ($export_files ) {
166176 print RESULT_OUTPUT " ,\" Export Filename\" " ;
167177 }
@@ -196,7 +206,12 @@ sub mine_file {
196206 # Make sure we don't mess up our original
197207 (my $original_file_volume , my $original_file_directory , my $original_file_name ) = File::Spec-> splitpath($original_file );
198208 $output_db_file = $original_file_name ;
199- $output_db_file =~ s / (\. [^.]*)/ .investigated$1 / ;
209+ $output_db_file =~ s /\. investigated\. ?// g ;
210+ if ($output_db_file =~ s / (\. [^.]*)/ .investigated$1 / ) {
211+ # $output_db_file =~ s/(\.[^.]*)/.investigated$1/;
212+ } else {
213+ $output_db_file .= " .investigated" ;
214+ }
200215 my $output_db_file = File::Spec-> catfile($run_folder ,$output_db_file );
201216 copy($original_file , $output_db_file ) or die " Can't copy $original_file to $output_db_file - $! \n " ;
202217 print " SQLite file: " .File::Spec-> abs2rel($output_db_file )." \n " if $verbose ;
@@ -205,7 +220,7 @@ sub mine_file {
205220 if ($export_files ) {
206221 $export_directory = File::Spec-> catdir($run_folder , " exports" );
207222 mkdir $export_directory ;
208- print " Export folder: ' " .File::Spec-> abs2rel($export_directory )." ' \n " if $verbose ;
223+ print " Export folder: " .File::Spec-> abs2rel($export_directory )." \n " if $verbose ;
209224 }
210225
211226 # Set up database connection
@@ -336,7 +351,14 @@ sub check_column_for_fun {
336351 }
337352
338353 # Print out to the target CSV file
339- print RESULT_OUTPUT " \" $file_name \" ,\" $tmp_table_name \" ,\" $column_name \" ,\" $primary_key_column \" ,\" $tmp_primary_key \" ,\" $file_type \" " ;
354+ (my $tmp_volume_for_output , my $tmp_directory_for_output , my $tmp_filename_for_output ) = File::Spec-> splitpath($file_name );
355+ print RESULT_OUTPUT " \" " .File::Spec-> abs2rel($tmp_directory_for_output )." \" ," .
356+ " \" $tmp_filename_for_output \" ," .
357+ " \" $tmp_table_name \" ," .
358+ " \" $column_name \" ," .
359+ " \" $primary_key_column \" ," .
360+ " \" $tmp_primary_key \" ," .
361+ " \" $file_type \" " ;
340362
341363 # Save out the blob if we're exporting files
342364 if ($export_files ) {
@@ -357,12 +379,13 @@ sub check_column_for_fun {
357379 }
358380
359381 # Export the file
360- print " \t Exporting file as " .File::Spec-> abs2rel($tmp_export_file_path )." \n " if $very_verbose ;
382+ (my $tmp_export_volume_for_output , my $tmp_export_directory_for_output , my $tmp_export_filename_for_output ) = File::Spec-> splitpath($tmp_export_file_path );
383+ print " \t Exporting file as $tmp_export_filename_for_output \n " if $very_verbose ;
361384 open (OUTPUT, " >$tmp_export_file_path " );
362385 binmode (OUTPUT);
363386 print OUTPUT $tmp_data_blob ;
364387 close (OUTPUT);
365- print RESULT_OUTPUT " ,\" $tmp_export_file_path \" " ;
388+ print RESULT_OUTPUT " ,\" $tmp_export_filename_for_output \" " ;
366389 }
367390
368391 # Update the database if we're decompressing values
0 commit comments