#!/usr/bin/perl; use strict; use warnings; use File::Copy; use File::Spec; use Archive::Rar; my $basepath='/home/kami'; my $workdir='name'; my $subdir='TEST2'; my $endung='.txt'; my $destdir='/home/backup'; my $archive_name='backupxxx.rar'; my $source_dir=File::Spec->join($basepath, $workdir); # '/home/kami/name/*.txt' my $glob_dir=glob(File::Spec->join($source_dir, '*'.$endung)); # *.txt existiert if(glob($glob_dir)) { print "In $source_dir existeiert mindestens eine Datei mit Endung $endung\n"; } # TEST2 existiert if(-d File::Spec->join($source_dir, $subdir)) { print "In $source_dir existeiert das Verzeichnis $subdir\n"; } # kopieren/verschieben for my $source_path (glob($glob_dir)) { if(-f $source_path) { my (undef,undef,$file) = File::Spec->splitpath( $source_path ); my $dest_path=my $glob_dir=glob(File::Spec->join($destdir, $file)); # move($source_path,$dest_path) or die("ERROR move($source_path,$dest_path) $!\n"); copy($source_path,$dest_path) or die("ERROR copy($source_path,$dest_path) $!\n"); } } # Archivieren my $rar = Archive::Rar->new(-archive => File::Spec->join($destdir, $archive_name) ); $rar->Add( -files => [glob($glob_dir)] );