Leser: 23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
#!/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)] );
my $glob_dir=File::Spec->join($source_dir, '*'.$endung);
print grep m#\.txt\z#, dir("/var/tmp")->children
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/usr/bin/perl -w use strict; use warnings; use Getopt::Long; use File::Copy; use File::Spec; use File::Glob ':glob'; my ($source_path, $txt_check, $verzeichnis, $dest_path,$file); my %options = (); GetOptions(\%options, 'txt=s'); my $downloaddir='/home/kami/download'; my $finaldir='/home/kami/final'; $verzeichnis=File::Spec->join($downloaddir, $options{'txt'}); # TXT Dateien suchen und kopieren $txt_check=File::Spec->join($verzeichnis, '*.txt'); print $txt_check."\n"; if(glob($txt_check)) { print "1"; for $source_path (bsd_glob($txt_check)) { print $source_path."\n"; if(-f $source_path) { (undef,undef,$file) = File::Spec->splitpath( $source_path ); $dest_path=$nfo_check=bsd_glob(File::Spec->join($finaldir, $file)); print $dest_path."\n"; copy($source_path,$dest_path) or die("ERROR copy($source_path,$dest_path) $!\n"); } } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/usr/bin/perl -w use strict; use warnings; use Getopt::Long; use File::Copy; use File::Spec; use File::Glob ':glob'; my ($source_path, $txt_check, $verzeichnis, $dest_path,$file); my %options = (); GetOptions(\%options, 'txt=s'); my $downloaddir='/home/kami/download'; my $finaldir='/home/kami/final'; $verzeichnis=File::Spec->join($downloaddir, $options{'txt'}); # TXT Dateien suchen und kopieren $txt_check=File::Spec->join($verzeichnis, '*.txt'); print $txt_check."\n"; if(glob($txt_check)) { print "1"; for $source_path (bsd_glob($txt_check)) { print $source_path."\n"; if(-f $source_path) { (undef,undef,$file) = File::Spec->splitpath( $source_path ); $dest_path=$nfo_check=bsd_glob(File::Spec->join($finaldir, $file)); print $dest_path."\n"; copy($source_path,$dest_path) or die("ERROR copy($source_path,$dest_path) $!\n"); } } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#!/usr/bin/perl -w use strict; use warnings; use Getopt::Long; use File::Copy; use File::Spec; use File::Glob ':glob'; my ($source_path, $txt_check, $verzeichnis, $dest_path,$file); my %options = (); GetOptions(\%options, 'txt=s'); my $downloaddir='/home/kami/download'; my $finaldir='/home/kami/final'; $verzeichnis=File::Spec->join($downloaddir, $options{'txt'}); # TXT Dateien suchen und kopieren $txt_check=File::Spec->join($verzeichnis, '*.txt'); print $txt_check."\n"; if(bsd_glob($txt_check)){ print "1\n"; for $source_path (bsd_glob($txt_check)){ print "SOURCE $source_path\n"; if(-f $source_path){ (undef,undef,$file) = File::Spec->splitpath( $source_path ); $dest_path=File::Spec->join($finaldir, $file); print "DEST $dest_path\n"; copy($source_path,$dest_path) or die("ERROR copy($source_path,$dest_path) $!\n"); } } }
2010-03-28T20:01:16 kamiIch bin leider nicht so ein großer PHP crack.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
$rar_check=File::Spec->join($verzeichnis, '*.rar'); if(bsd_glob($rar_check)) { for $source_path (bsd_glob($rar_check)) { if(-f $source_path) { (undef,undef,$file) = File::Spec->splitpath( $source_path ); my $rar = Archive::Rar->new(-archive => bsd_glob($source_path) ); $rar->Extract( -files => $finaldir, -quiet => 1 ); print "Das file ".$source_path." wird nach ".$finaldir." entpackt.\n"; } } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
my $rar_check=File::Spec->join($verzeichnis, '*.rar'); if(bsd_glob($rar_check)) { for $source_path (bsd_glob($rar_check)) { if(-f $source_path) { print "Das file ".$source_path." wird nach ".$finaldir entpackt."; my $rar = Archive::Rar->new(-archive => $source_path ); my $res=$rar->Extract(-files=>qq("$finaldir"), -quiet => 1 ); die "Error $res in extracting from $archive\n" if ( $res ); entpackt.\n"; } } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
my $rar_check=File::Spec->join($verzeichnis, '*.rar'); if(bsd_glob($rar_check)) { for $source_path (bsd_glob($rar_check)) { if(-f $source_path) { print "Das file ".$source_path." wird nach ".$finaldir entpackt."; my $rar = Archive::Rar->new(-archive => "../../..".qq("$source_path"); my $res=$rar->Extract(-files=>qq("$finaldir"), -quiet => 1 ); die "Error $res in extracting from $archive\n" if ( $res ); entpackt.\n"; } } }
2010-03-30T06:50:43 kamiCode (perl): (dl )1 2 3if(-f $source_path) #... my $rar = Archive::Rar->new(-archive => "../../..".qq("$source_path");
Weil er sonst immer noch die Unterverzeichnisse mit vor den Path dran hängt in denen das Skriptfile liegt. Wie kann ich das noch schöner machen?
1 2
$source_path = File::Spec->abs2rel( $source_path ) ; $source_path=qq("$source_path");
1 2 3
my ($volume,$directories,$file) = File::Spec->splitpath( $path ); $directories=File::Spec->catdir(map{qq("$_")}File::Spec->splitdir( $directories )); $source_path=File::Spec->catpath( $volume, $directories, qq("$file"));
2010-03-30T16:59:27 kamiDas einzige Problem ist nur das die Variable die für die Auswahl des Archives verwendet wird für diesen Fall immer noch den PATH von dem Skript wo es ausgeführt wird mit enthält.
1
2
3
4
# kein Schleifendurchlauf, wenn kein Treffer
for my $src_path ( bsd_glob($rar_check) ) {
}