Thread Funktionen für Dateihandling gesucht (21 answers)
Opened by kami at 2010-03-28 13:06

Gast wer
 2010-03-28 15:04
#135396 #135396
Code (perl): (dl )
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)] );

Last edited: 2010-03-28 15:08:38 +0200 (CEST)

View full thread Funktionen für Dateihandling gesucht