On Thursday, May 30, 2002, at 01:40 , Johnson, Shaunn wrote:

> Question about capturing a file name with
> spaces using regular expressions.
[..]
> The output looks like this (the result of just $group).
>
> [snip example]
>
> /samba/hmp/iso/06/UNASSIGNED-06 - DUMMY-06.iso
>
> [/snip example]
>
> My goal is to print "UNASSIGNED-06 - DUMMY-06.iso"  (and
> then later on cut out the .iso part).  If I can do that,
> then I think I can do the rest.
>
> Suggestions?

perldoc -f readdir

Remember that the 'directory' portion is not in the 'dirBlock'
itself - only the names of files....

traditionally we do

        my $demDir = '/Users/drieux/tmp/Junk';

        opendir(DIR, $demDir) or die "unable to open Dir $demDir:$!\n";
        my @files = grep { $_ ne '.' and $_ ne '..' } readdir(DIR);
        close(DIR);

        foreach my $file (@files) {
                print "we see file :$file:\n";

                open(FH, "$demDir/$file") or die "funny I can not open $file:$! \n";
                print $_ while <FH>;
                close FH;
                print "\n# -thus endeth the reading of \$file $file-\n\n";
        }

which in my case generates up

        we see file :parseForSpaces.pl:
        #!/usr/bin/perl -w
        use strict;

        # #FILENAME#- is for

        my $demDir = '/Users/drieux/tmp/Junk';

        opendir(DIR, $demDir) or die "unable to open Dir $demDir:$!\n";

        my @files = grep { $_ ne '.' and $_ ne '..' } readdir(DIR);
        close(DIR);

        foreach my $file (@files) {
                print "we see file :$file:\n";
                open(FH, "$demDir/$file") or die "funny I can not open $file:$! \n";
                print $_ while <FH>;
                close FH;
                print "\n# -thus endeth the reading of \$file $file-\n\n";
        }
        

        # ginned On #CREATIONDATE#
        # #real_url#
        # end of the world as I knew it [EMAIL PROTECTED] all rights reserved
        # -thus endeth the reading of $file parseForSpaces.pl-

        we see file :untitled text with spaces in name:
        This is a File with Space in the Name of it

        # -thus endeth the reading of $file untitled text with spaces in name-

note that I embedded the "$file" between colons so that you
can see what is in the 'list of files' I got from that directory.

Also note that to be able to read those files, we either need
to fully qualify the path, as I prefer - or chdir in, which
I do not prefer....

Note that this also avoids having to File::Basename off the
path elements - since, well you din't put them in there to
begin with, as you opened up the inode, it happened to be
a directory, and walked through it getting the pretty file
names themselves...

ciao
drieux

---


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to