On 17 Oct 2006 at 13:16, Perl beginners wrote:
> Hi All,
>
> I am knocking my head against a wall trying to work with directories
> with spaces.
>
> I need to translate some file paths like the one below:
>
> /data/scanning/phil/edits/gary/finished/STI 9-10-06/E0102.tif
>
> into
> /var/www/phil/pix/E0102.jpg
>
> (I need the path to the tif to make the jpeg).
>
> If I glob the files in the parent directory and then File::Basename I
> end up with 'STI' as the filename and the rest of the program fails.
>
> foreach my $d (@dirs) {
> print STDERR "reading files from $d.\n";
> my @tif = glob("$d/*tif");
> foreach my $t (@tif) {
> my $base = basename("$t");
> (my $j = $base) =~ s/tif$/jpg/;
> print STDERR "Found $base $j $t\n";;
> push(@names,$n);
> }
> }
>
> Is there some quoting scheme I should be using? Or do I have to use a
> regex to grab the filename from the end of the string?
I opted for the readdir() function instead. Worked a treat and was
less code.
foreach my $d (@dirs) {
print STDERR "reading directory $d\n";
opendir(DIR,$d) || die "Can't open $d: $!\n";
@names = grep {! /^\./ && -f "$d/$_" && "$d/$_" =~
/(tiff|tif)$/} readdir(DIR);
}
Thanx.
Dp.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>