in reply to working with directories
Also note that readdir returns the file names, but you have to prefix the path to them. Also, you only want to open files, not subdirectories, so I used grep to filter those out.
#!/usr/bin/perl use warnings; use strict; my $path = '/Users/Maxi/Desktop/Verzeichnis beispiel'; opendir my $DIR, $path or die " the directory couldn't be opened\n"; my @folder = grep -f "$path/$_", readdir $DIR; for my $file (@folder) { open my $FIL ,'<', "$path/$file" or die "the file $file couldn't b +e opened: $!\n"; while (<$FIL>) { print if /perl/i; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: working with directories
by madM (Beadle) on Sep 12, 2013 at 13:57 UTC | |
by choroba (Cardinal) on Sep 13, 2013 at 07:23 UTC | |
by madM (Beadle) on Sep 14, 2013 at 11:27 UTC | |
by choroba (Cardinal) on Sep 14, 2013 at 16:23 UTC |