in reply to convert directory content to dbf
The 2 standard ways to get the contents of a directory are glob and opendir (followed by readdir and closedir).
Here's an example of the latter:
# Assuming you want to read files in directory $dir opendir(my $fh, $dir) or die "Can't read directory '$dir' ($!)\n"; my @files = readdir($fh); closedir($fh); foreach my $file (@files) { next if ($file eq "." or $file eq ".."); # Skip self and parent my $path = "$dir/$file"; # Construct full pathname if (-f $path) { # Do something with regular file $path ... } elsif (-d $path) { # Do something with subdirectory $path ... } }
Note that you need to construct the full pathname, since readdir gives you only the basename of each file/subdirectory.
|
|---|