#!/usr/bin/perl # NOTE: The above path is machine dependent!!! #------------------------------------------------------------------------ # file: 780archive.pl # # Update the version number and the Revision History after changes # $version = "0.90 [28-Dec-2005]"; #------------------------------------------------------------------------ # # This Perl script calls the tar ("Tape ARchive") command to make # a compressed archive of files and subdirectories. # # Author: Dick Furnstahl # furnstahl.1@osu.edu # # Revision history: # 0.90 28-Dec-05 --- original version, using ideas from the Perl Cookbook # # Linux usage notes: # * # # To Do: # * more advanced options # # # Load Perl packages use Getopt::Long; # allow the extended processing of command line options # set default options # (none for now) # Get the command-line options # GetOptions("help", "version"); # print out version info and/or help if requested if ($opt_version) { print "\nVersion number: $version\n"; } # print out help if requested if ($opt_help) { print_help(); } # quit if version info or help requested if ($opt_version || $opt_help) { exit 1; } # get the name of the archive print "What do you want to call the archive?\n"; print " (Note \".tarz\" will be appended to your answer)\n"; print " Archive name: "; chomp($archive_base=); if ($archive_base) { $archive_name = $archive_base . ".tarz" } print "\n **** Creating $archive_name ****\n"; # get a list of files to archive $this_dir = "./"; @all_files = (); opendir(DIR,$this_dir) or die "can't opendir $this_dir: $!"; while ( defined ($file = readdir DIR) ) { next if $file =~ /^\.\.?$/; # skip . and .. push(@all_files, $file) # if -T "$this_dir/$file"; # -T for text files } closedir DIR; print "\nSelect from these files and subdirectories:\n"; file_select(@all_files); # returns @selected_files $tar_command = "tar cfvz $archive_name @selected_files"; print "\nFiles included in the archive:\n"; system($tar_command); print "\n\n **** Created $archive_name ****\n"; exit 0; #************************************************************************* #************************************************************************* # ==================================================================== # name: print_help # This subroutine prints the help info. # ==================================================================== sub print_help { print <); if ($answer eq "y" || $answer eq "Y") { @selected_files = @_; } else { print "\n Enter the numbers of EVERY file you want to include, \n"; print " separated by spaces, then at the end.\n"; print " Numbers: "; chomp($choices=); @choice_list = split(" ", $choices); @selected_files = (); foreach $selected (@choice_list) { push(@selected_files, @_[$selected-1]); } } } #************************************************************************* #*************************************************************************