Home > Archive > PERL Beginners > January 2006 > Glob with spaces
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Dave DiGregorio 2006-01-25, 6:57 pm |
| Is there a way to glob if the directory path has spaces?
The following does not work
$sourcePath = "C:/Documents and Settings/xyz/abc ;
files = glob $sourcePath ;
Thanks
David R. DiGregorio
Vocollect
703 Rodi Road
Pittsburgh, PA 15235
P. 412-349-2440
ddigregorio@vocollect.com
-CONFIDENTIAL, PRIVILEGED COMMUNICATION-
This e-mail transmission is private and intended for the addressee(s)
only. It may contain information that is privileged and/or
confidential. If you have received this transmission in error, you are
not authorized to read, copy, disclose or disseminate it in any manner.
If you have received it in error, please delete it and all copies
(including backup copies) that have been made, and transmit a reply
message informing the sender that it was misdirected.
| |
| Chas Owens 2006-01-25, 6:57 pm |
| On 1/25/06, DiGregorio, Dave <ddigregorio@vocollect.com> wrote:
> Is there a way to glob if the directory path has spaces?
>
> The following does not work
>
> $sourcePath =3D "C:/Documents and Settings/xyz/abc ;
>
> files =3D glob $sourcePath ;
This seems to work:
my @files =3D glob("C:/Documents\\\ and\\\ Settings/user/*");
print "[$_]\n" for @files;
| |
| Paul Lalli 2006-01-26, 7:55 am |
| Dave DiGregorio wrote:
> Is there a way to glob if the directory path has spaces?
The exact same way you'd do it on the command line.
> The following does not work
>
> $sourcePath = "C:/Documents and Settings/xyz/abc ;
>
> files = glob $sourcePath ;
You need to tell the command line interpreter that you have one
argument, that the whole string is your argument. On the command line,
you have to enclose the whole thing in quotes, or backslash each space.
You have to do the same thing in Perl:
@files = glob "\"$sourcePath\"";
or, more readable:
@files = glob qq{"$sourcePath"};
That is, the string you pass to glob has to actually have the ""
surrounding it.
Paul Lalli
| |
| Paul Lalli 2006-01-26, 7:55 am |
|
Chas Owens wrote:
> On 1/25/06, DiGregorio, Dave <ddigregorio@vocollect.com> wrote:
>
> This seems to work:
>
> my @files = glob("C:/Documents\\\ and\\\ Settings/user/*");
Yes, that does work, but you're creating far too much work for
yourself.
If you put your string in single quotes rather than double, there's no
need for all the extra backslashes:
my @files = glob ('C:/Documents\ and\ Settings/user/*');
Or, my preference, surround the whole thing in quotes so you don't need
to backslash anything:
my @files = glob(qq{"C:/Documents and Settings/user/*"});
Paul Lalli
|
|
|
|
|