Thread Einlesen mehrerer Dateien (38 answers)
Opened by Alex at 2013-04-23 11:08

Linuxer
 2013-04-29 11:07
#167351 #167351
User since
2006-01-27
3870 Artikel
HausmeisterIn

user image
Hi,

hier mal ein Schnellschuß, der alle .ffn pro Verzeicnis ausliest.

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
49
50
51
#! /usr/bin/perl
use strict;
use warnings;

# https://www.perl-community.de/bat/poard/thread/18288

use File::Find;                             # for searching for files/directories
use File::Spec::Functions qw( catfile );    # for creating portable file-paths
use Cwd;                                    # for determing current work directory

my @directories = (
    cwd,                                    # search in current work directory
);


my @matches;                                # storage for matching file paths




sub find_ffn_files {

    return if ! -d $File::Find::name;       # skip if not a directory

    my $dir = $File::Find::name;            # short name of directory

    opendir my $dh, $dir   or die "Cannot open '$dir': $!\n";
    # read '.ffn'  files from directory and create full file path
    my @files = map { catfile( $dir, $_ ) } grep { m/\.ffn$/ } readdir $dh;
    closedir $dh;

    # create array of array for matches
    push @matches, \@files      if @files;

}


# search for files and fill @matches
find( \&find_ffn_files, @directories );


# check @matches
for my $matching_dir ( @matches ) {

    # each matching_dir is an array reference which contains
    # the full paths of the files found

    #  process .ffn files per directory
    print join( " ", sort { $a cmp $b } @{ $matching_dir } ), "\n";

}
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!

View full thread Einlesen mehrerer Dateien