#!/usr/bin/perl ## ## Author: David McKeon <@bonzoli.com> ## URL: http://bonzoli.com ## Program: joinsplit ## Creation Date: Date: 2007/01/30 19:35:58 PST ## Last Revision: 2007/01/30 19:35:58 PST ## Version : v.5 ## ############################################################################# # David McKeon <@bonzoli.com> http://bonzoli.com # # # # Copyright (C) 2007-2007 David McKeon. All rights reserved. # # # # This program is free software; you can redistribute it and/or modify it # # under the terms of the GNU General Public License as published by the # # Free Software Foundation; either version 2 of the License, or (at your # # option) any later version. # # # # This program is distributed in the hope that it will be useful, but # # WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # # Public License for more details. # # # # You should have received a copy of the GNU General Public License along # # with this program; if not, write to: # # # # Free Software Foundation, Inc. # # 59 Temple Place - Suite 330 # # Boston, MA 02111-1307, USA. # # # # Or you can find the full GNU GPL online at: http://www.gnu.org # # # ############################################################################# ## Category: Perl ## ## ## ## ## # $| = 1; my $USAGE="Usage: joinsplit NOTE: .00 or .001 extension, use the lowest to start, one file only needed on command line.\n"; if (! $ARGV[0]) { print "$USAGE\n"; exit; } use Getopt::Long; use File::Path; # create paths/dirs # Directory to place part files that were used to assemble the final file # We move them here to help keep the clutter down my $DMDIR='deleteme'; # This makes the dir if it doesn't exist make_dir($DMDIR); #--------------------------------------------------------------------------- Getopt::Long::Configure("no_ignore_case"); GetOptions( "h|help" => \$help, "V|version" => \$vers, #----------------------- ); #--------------------------------------------------------------------------- if($help){ exec("perldoc $0"); } if($vers){ version(); } #--------------------------------------------------------------------------- #--------------------------------------------------------------------------- sub version { my($date) = "2007/01/30 16:35:58 GMT"; my($rvsn) = ".5"; my($rcsd) = ".5"; $date =~ s/(.*: +)(.*?)(\s*$)/$2/g; $rvsn =~ s/(.*: +)(.*?)(\s*$)/$2/g; $rcsd =~ s/(.*: +)(.*?)(\s*$)/$2/g; print < URL: http://bonzoli.com Creation Date: 2007/01/30 16:35:58 GMT Last Revision: $date GMT Revision: $rcsd Copyright (C) 2007-2007 David McKeon. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to: Free Software Foundation, Inc. 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA. Or you can find the full GNU GPL online at: http://www.gnu.org EOF exit; } sub shellify_string { ########################################################################## # FUNCTION DEFINITIONS #------------------------------------------------------------------------- # FUNCTION shellify_string # RECEIVES $string # RETURNS $string # DOES Going to make this line readable by shell, so mv's and copies work. # add a backslash before unusual characters my ( $file ); # shouldn't just shift work here? $file = shift @_; #print "my file is $file \n"; #If its not one of these characters put a \ in front of it. $file =~ s|[^-a-zA-Z0-9_.,/]|\\$&|g; # backslash newline gets ignored by sh, so we have to use quotes. $file =~ s|\\\n|'\n'|g; # make sure name doesn't have a leading - $file =~ s|^-|./-|; # null name is unprintable, make it '.' if ($file eq '') { $file = "."; } return $file; } sub make_dir { ########################################################################## # FUNCTION DEFINITIONS #------------------------------------------------------------------------- # FUNCTION make_dir # RECEIVES directory including full path # DOES Makes the full path and dir needed for the deleteme files. $NEWDIR=shift; eval { mkpath("$NEWDIR", 1, 0755) }; if ($@) { print "Couldn\'t create $NEWDIR: $@"; } } ##MAIN####################################################################### my $file = $ARGV[0]; chomp $file; print "$file\n"; # This sets the max parts to look for, You could raise this # if you have more files. my $i=1000; my $NUM; my $NF,$WF, $Dig, $zeros; $_=$file; ($NUM)=/\.0{1,2}(\d)$/; my $LOWNUM=$NUM; #print "NUM=$NUM\n"; #.01 or .001 extension if( ! -f $file || $file !~ m/\.0{0,2}$NUM$/){ print "\nSomething wrong with file: $file\n $USAGE"; exit;} if ($file =~ /\.0$NUM$/) { $Dig='%02.d'; #print "Found .0$NUM,$Dig\n"; } elsif ($file =~ /\.00$NUM$/) { $Dig='%03.d'; #print "Found .00$NUM,$Dig\n"; } else { print "\n Can not determine file type. exiting..\n"; exit; } $file=~s/\.0{1,2}$NUM$//g; #print "FILE=$file,$Dig\n"; my $WF=$file; my $NF=shellify_string($WF); mkdir $DMDIR, 0755; while ( $NUM<$i ) { #print "$Dig,$NN, $WF\n"; my $NN=sprintf $Dig, $NUM; #print "NUM=$NN\n"; $WF="$file.$NN"; #print "$Dig,$NN, $WF\n"; print "Work file $WF to New File $NF\n\n\n"; if (!(-d $WF) && (-f $WF) && $WF=~/\.[0-9]{2,3}$/ && !($WF=~/\.([Pp][Dd][Ff])$/)) { #print "NEXT!\n"; if ($WF=~/\.0{1,2}$LOWNUM$/) { $WF=shellify_string($WF); $CMD="cp $WF $NF"; #print "$CMD\n"; system($CMD) == (0) or print "system $CMD failed: $?"; $CMD="mv $WF $DMDIR/"; #print "$CMD\n"; system($CMD) == (0) or print "system $CMD failed: $?"; } elsif ($WF=~/.[0-9]{2,3}$/) { $WF=shellify_string($WF); $CMD="/bin/cat $WF >> $NF"; #print "$CMD\n"; system($CMD) == (0) or print "system $CMD failed: $?"; $CMD="mv $WF $DMDIR/"; #print "$CMD\n"; system($CMD) == (0) or print "system $CMD failed: $?"; } } else { # Its not valid split file, exiting loop now $NUM=1000001; } $NUM++; } ##End Main################################################################## #--------------------------------------------------------------------------- ## ## Use "perldoc joinsplit" to read the man page below. # __END__ =head1 NAME B - Is a program that joins split, a split or csplit file. =head1 SYNOPSIS B S<[ B<-hv> ]> S<[ I ]> =head1 DESCRIPTION B Is a program that joins split, a split or csplit file, is simply a file that was cut into chunks to make it easier to send. Ussually the file have a .00, .01, .000, or .001 type extension, and there could be hundreds of files. This program puts the original file back together, then moves all the chunks to a delete me directory to keep the clutter down. If the directory doesn't exist =head1 QUICK START The most common usage is as follows: B NOTE: .00 or .001 extension, use the lowest to start, one file only needed on command line. =head1 STANDARD OPTIONS B<-h --help> Prints this information. B<-v --version> Prints version information. =head1 OPTIONS =head1 EXAMPLE The example below B I =head1 BUGS None. =head1 SEE ALSO joinsplit, split, csplit =head1 AUTHOR AND COPYRIGHT David McKeon <@bonzoli.com> http://bonzoli.com Copyright (C) 2007-2007 David McKeon. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to: Free Software Foundation, Inc. 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA. Or you can find the full GNU GPL online at: http://www.gnu.org =head1 VERSION Current Revision: $Revision$ Last Modification: v.5 =pod SCRIPT CATEGORIES UNIX/System_administration =pod OSNAMES Any