1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
my $test = make_path( '' , { error => \my $err } );
if ( $err && @$err )
{
for my $diag ( @$err )
{
my ( $file, $message ) = %$diag;
if ( $file eq '' )
{
print "general error: $message\n";
} else {
print "problem unlinking $file: $message\n";
}
}
} else {
print "No error encountered\n";
}
1
2
3
4
make_path( '*' , { error => \$LG_FH_Directory_Error } );
if ( $LG_FH_Directory_Error && @$LG_FH_Directory_Error ) { $LG_FH_Directory_Status = '1'; }
if ( !$LG_FH_Directory_Error || !@$LG_FH_Directory_Error ) { $LG_FH_Directory_Status = '0'; }
2021-05-24T10:53:22 YAPDMeine Frage ist nun, wann tritt denn der Fall ein, dass $file eq ' ' ist ?
2021-05-24T10:53:22 YAPDDes weiteren würde es für den Zweck der Überprüfung, ob das Verzeichnis
erstellt wurde, doch reichen, wenn ich einfach den Status definiere, oder ?
1
2
3
4
5
6
$path = "C:\Test\Logs;
make_path( '$path' , { error => \$LG_FH_Directory_Error } );
if ( $LG_FH_Directory_Error && @$LG_FH_Directory_Error ) { $LG_FH_Directory_Status = '1'; }
if ( !$LG_FH_Directory_Error || !@$LG_FH_Directory_Error ) { $LG_FH_Directory_Status = '0'; }
2021-05-24T13:15:34 YAPDHi Haj,
ich habe gesehen, dass du online bist und gehofft, dass du auf meinen
Beitrag antwortest :)
2021-05-24T13:15:34 YAPDIch habe den Code gerade nochmal geändert :
$LG_FH_Directory_Status = (-d $path) || make_path( $path ) ? 0 : 1;
make_path( '$path' , { error => \$LG_FH_Directory_Error } );
2021-05-24T13:15:34 YAPDIch habe verschiedene Szenarien getestet, z.B. mit ungültigen Zeichen
wie '*' oder wenn die variable leer ist. Es hat immer funktioniert,
er hat also den richtigen Status zurückgegeben.
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
sub Create_Directory {
my ( %Parameter ) = @_;
print "PARAMETER : $Parameter{ Directory }" . "\n";
my ( @Directories_Store ) = split( /\// , $Parameter{ Directory } );
my $Directories_Store_Counter = @Directories_Store;
my $Device = substr( $Parameter{ Directory } , 0 , 2 );
splice @Directories_Store, 0 , 1;
my $DIR;
my $Errors = 0;
foreach my $Directory( @Directories_Store )
{
$DIR .= '/' . $Directory;
my $FH_Directory = $Device . $DIR;
if( !( -e $FH_Directory ) )
{
print "[ INFO ] The directory '$FH_Directory' could not be found !" . "\n";
my $FH_Diretory_Status = mkdir( $FH_Directory , 0777 );
if( $FH_Diretory_Status eq '0' )
{
print "[ ERROR ] The directory '$FH_Directory' could not be created !";
return 'Failure';
}
if( $FH_Diretory_Status eq '1' )
{
print "[ INFO ] The directory '$FH_Directory' was created successfully !" . "\n";
}
} else {
print "[ INFO ] The directory '$FH_Directory' already exists !" . "\n";
}
}
return 'Success';
}