Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2005-09-16
00:16 • Closed ticket [1292143fff]: glob does not accept backslash for directory separto... artifact: 535a0488fa user: vincentdarley
00:09 • Pending ticket [1292143fff]. artifact: ce45fd8a66 user: dgp
00:04 • Ticket [1292143fff]: 4 changes artifact: 9c521cd82d user: dgp
2005-09-15
16:50 • New ticket [1292143fff]. artifact: 98ab4d25d3 user: gwlester

glob does not accept backslash for directory separtor

Closed / Invalid1292143fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-09-15 16:50:22
When using windows native file separator on Windows XP
glob returns incorrect results (see example below).

(bin) 65 % set foo
C:\Clients\LMMSS\PMES\Source\CAPP\Procs\interfaces\copics\item_master\*
(bin) 66 % set bar
C:/Clients/LMMSS/PMES/Source/CAPP/Procs/interfaces/copics/item_master/*
(bin) 67 % glob $foo
no files matched glob pattern
"C:\Clients\LMMSS\PMES\Source\CAPP\Procs\interfaces\copics\item_master\*"
(bin) 68 % glob $bar
C:/Clients/LMMSS/PMES/Source/CAPP/Procs/interfaces/copics/item_master/brasfile
C:/Clients/LMMSS/PMES/Source/CAPP/Procs/interfaces/copics/item_master/LoadItemMaster.tcl
dgpplain2005-09-16 00:04:51
Logged In: YES 
user_id=80530


Not a fix, but consider using
[glob -directory] as a workaround.
dgpplain2005-09-16 00:09:38
Logged In: YES 
user_id=80530


I think this excerpt from 
glob.n explains it:

"Since the backslash character has a special meaning to the glob
command, glob patterns containing Windows style path
separators need
special care. The pattern \fIC:\e\efoo\e\e*\fR is interpreted as
\fIC:\efoo\e*\fR where \fI\ef\fR will match the single
character \fIf\fR
and \fI\e*\fR will match the single character \fI*\fR and
will not be
interpreted as a wildcard character. One solution to this
problem is
to use the Unix style forward slash as a path separator.
Windows style
paths can be converted to Unix style paths with the command
\fBfile
join $path\fR (or \fBfile normalize $path\fR in Tcl 8.4)."
vincentdarleyplain2005-09-16 00:16:29
Logged In: YES 
user_id=32170

Glob does handle windows native separators just fine, but
you need to read the glob man page where you will see that
glob interprets:

\x  (backslash-x)

as an attempt to match the character x.  Hence you will need
to double up your backslashes if you want glob to interpret
them as directory separators.  If you read the end of the
glob man page, you will see this:

Since the backslash character has a special meaning to the glob 
command, glob patterns containing Windows style path
separators need 
special care. The pattern \fIC:\e\efoo\e\e*\fR is
interpreted as 
\fIC:\efoo\e*\fR where \fI\ef\fR will match the single
character \fIf\fR 
and \fI\e*\fR will match the single character \fI*\fR and
will not be 
interpreted as a wildcard character. One solution to this
problem is 
to use the Unix style forward slash as a path separator.
Windows style 
paths can be converted to Unix style paths with the command
\fBfile
join $path\fR (or \fBfile normalize $path\fR in Tcl 8.4). 

which explains exactly your problem.
Log in (anonymous is fine) to add a comment.