|< 1 2 >| | 12 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use strict;
use warnings;
my $dir = "c:/test";
my @array;
GetDirs($dir);
sub GetDirs {
my ($directory) = @_;
opendir(DIR, $directory) or die "Error: couldn't open directory '$directory': $\n";
foreach my $entry (readdir(DIR))
{
push (@array, $entry);
}
close (DIR);
} #End GetDirs
print "@array";
1
2
3
4
5
6
7
8
SUB_STRUCT
SPRINGE IN ORDNER
FALLS ORDNER LEER -> ENDE
SONST ERSTELLE ARRAY
SCHREIBE ALLE DATEINAMEN UND ORDNERNAMEN IN ARRAY
STARTE SUB_STRUCT
ENDE SUB
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
use strict;
use warnings;
my $dir = "c:/test";
my @array;
GetDirs($dir, \@array);
sub GetDirs {
my ($directory, $arrayref) = @_;
$directory =~ s!\\!/!g;
$directory =~ s!/$!!;
if(opendir(my $dir, $directory)) {
while(my %entry = readdir $dir) {
next if $entry =~ m!^\.\.$?!;
my $path = "$directory/$entry";
push @{$arrayref}, $path;
GetDirs($path, $arrayref) if-d $path;
}
closedir $dir;
}
} #End GetDirs
print join("\n", @array);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#! /usr/bin/perl
use strict;
use warnings;
use File::Find;
my $dir = "c:/test";
my @files = ();
find (sub {
if (-f $_) {
push (@files, $File::Find::name);
}
}, $dir);
foreach my $file (sort @files) {
print "Datei: $file\n";
} # foreach
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
use strict;
use warnings;
my $tree = {};
read_it('D:', $tree);
{
my $durchlauf;
sub read_it {
my ($dir, $tree) = @_;
my $name;
$name = (split(/\\/, $dir))[-1] if ($durchlauf);
$name = $dir unless ($durchlauf);
$durchlauf = 1;
my @file = ();
my @dir = ();
opendir(VERZ, $dir);
while (my $read = readdir(VERZ)) {
if (-d "$dir\\$read") {
push (@dir, "$dir\\$read") if ($read !~ /(\.)$/);
}
else {
push @file, $read;
}
}
closedir(VERZ);
$tree -> {$name} = { files => \@file };
foreach my $directory (@dir) {
read_it("$directory", \%{ $tree -> {$name} })
}
}
}
Quote$tree -> {$name} = { files => \@files };
$tree -> {$name} = { files => \@files };
QuoteWie kann ich z.B. alle Verzeichnisse, bzw alle Datein, bzw beides eines Bestimmten Ordner ausgeben....
|< 1 2 >| | 12 Einträge, 2 Seiten |