8 Einträge, 1 Seite |
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
sub entpacken { my $datei; my $check; my $verzeichnis = $_[0]; opendir(DIR, $verzeichnis); while($datei = readdir(DIR)) { if ($datei ne "." && $datei ne "..") { $check = $verzeichnis . $datei; if (-d $check) { $check = $check . "\/"; entpacken($check); } else { print $datei . "\n"; tue_was_mit_datei($datei); } } } closedir(DIR); }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#! /usr/bin/env perl
use strict;
use warnings;
use File::Find;
my $dir = './testdir';
my @files;
find(\&get_dir,$dir);
for my $file(@files){
tue_was_mit_datei($file);
}
sub get_dir{
push(@files,$File::Find::name) if(-f $File::Find::name);
}# get_dir
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use strict;
package Ox::Util;
use vars '$VERSION';
$VERSION = '0.01';
sub string_trim {
my ($str, $c) = @_;
$c ||= ' ';
$str =~ s!$c+$!!;
return ($str);
}
1;
use strict;
package Ox::File;
use vars '$VERSION';
$VERSION = '0.01';
use Ox::Util ();
sub fix {
my $path = shift || '';
$path =~ s!\\!/!g;
$path =~ s!/+!/!g;
return $path;
}
sub enum {
my %args = @_;
$args{dir} ||= '';
$args{depth} ||= 0;
$args{callback} ||= '';
return 0 unless ref $args{callback} eq 'CODE';
return 0 unless -d $args{dir};
$args{dir} = &fix($args{dir});
$args{dir} = Ox::Util::string_trim($args{dir}, '/');
my $handle;
if(opendir($handle, $args{dir})) {
while(defined(my $entry = readdir $handle)) {
next if $entry =~ /^\.\.?$/;
my $filename = $args{dir}.'/'.$entry;
if(-d $filename and ($args{depth} > 0 or $args{depth} < 0)) {
my %copyofargs = %args;
$copyofargs{dir} = $filename;
$copyofargs{depth}--;
enum(%copyofargs);
}
$args{callback}->($filename) if -f $filename;
}
closedir($handle);
}
return (1);
}
1;
1
2
3
4
5
6
7
8
9
10
11
12
13
use strict;
use warnings;
use Ox::File;
&Ox::File::enum(
dir => "C:\\",
depth => -1, # komplett rekursiv
callback => sub {
my ($filename) = @_;
print "$filename\n";
}
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#! /usr/bin/env perl
use strict;
use warnings;
use File::Find;
my $dir = './testdir';
my @files;
find(\&get_dir,$dir);
for my $file(@files){
tue_was_mit_datei($file);
}
sub get_dir{
push(@files,$File::Find::name) if(-f $File::Find::name);
}# get_dir
8 Einträge, 1 Seite |