Overview
| Artifact ID: | 5188a9a199f1b353bd1c0997dc2c959545ee3628 |
|---|---|
| Ticket: | 3eace1b21f66da738cd1769e4ec69cb0f50e6029
'glob -dir $path *' doesn't work for deeply nested paths |
| User & Date: | john.j.seal on 2015-07-07 17:20:42 |
Changes
- assignee changed to: "nobody"
- closer changed to: "nobody"
- cmimetype changed to: "text/html"
- comment changed to:
The command [glob -dir $path *] fails when $path is very deeply nested; this makes it impossible (AFAICT) to traverse a deeply nested directory hierarchy. It doesn't matter whether $path is a plain path, or begins with the //?/ long path prefix. Some (but not all) of the [file] commands can handle long paths, depending on the Tcl version. Here is a program that illustrates some of the deficiencies and differences: <pre> # Windows [glob] bug demo. For background info see: # https://groups.google.com/forum/#!topic/comp.lang.tcl/5awD6g40jrg # https://core.tcl.tk/tcl/tktview/1479814fffffffffffff # https://core.tcl.tk/tcl/tktview/3389978fffffffffffff catch {console show} puts "Tcl [info patchlevel]" update # Make a path >300 characters by adding 5 at a time. set lvl 0 set path [pwd] while {[string length $path] <= 300} { incr lvl append path /path } puts "Path length: [string length $path]" # Test whether [file mkdir] can create a directory under it. puts -nonewline "File mkdir with plain path" if {[catch {file mkdir $path/path} err]} { puts ": failed" puts -nonewline "File mkdir with long path prefix" if {[catch {file mkdir //?/$path/path} err]} { puts -nonewline ": failed" vwait forever } } puts "" # Test whether [file exists] can see it. if {[catch {file exists $path} exists]} {set exists "failed"} puts "File exists with plain path: $exists" if {[catch {file exists //?/$path} exists]} {set exists "failed"} puts "File exists with long path prefix: $exists" # Test whether [glob] can see it. if {[catch {llength [glob $path]} matches]} {set matches "failed"} puts "Glob with plain path: $matches" if {[catch {llength [glob //?/$path]} matches]} {set matches "failed"} puts "Glob with long path prefix: $matches" # Test whether [glob -dir] can see the subdirectory. if {[catch {llength [glob -dir $path *]} matches]} {set matches "failed"} puts "Glob -dir with plain path: $matches" if {[catch {llength [glob -dir //?/$path *]} matches]} {set matches "failed"} puts "Glob -dir with long path prefix: $matches" # Test whether [glob] can see the subdirectory. if {[catch {llength [glob $path/path]} matches]} {set matches "failed"} puts "Glob on subdir with plain path: $matches" if {[catch {llength [glob //?/$path/path]} matches]} {set matches "failed"} puts "Glob on subdir with long path prefix: $matches" # Test whether [file delete] can delete it. puts -nonewline "File delete with plain path" if {[catch {file delete -force [pwd]/path} err]} { puts ": failed" puts -nonewline "File delete with long path prefix" if {[catch {file delete -force //?/[pwd]/path} err]} { puts -nonewline ": failed" # Delete it iteratively. while {$lvl > 0} { incr lvl -1 file rename -force path/path tmp file delete -force path file rename -force tmp path } file delete -force path } } puts "" </pre> Here are the results for Tcl 8.6.4 and 8.5.17 (note that actually tested this using Tclkits, not full Tcl installs): <pre> Tcl 8.6.4 Path length: 301 File mkdir with plain path: failed File mkdir with long path prefix File exists with plain path: 1 File exists with long path prefix: 1 Glob with plain path: 1 Glob with long path prefix: 1 Glob -dir with plain path: failed Glob -dir with long path prefix: failed Glob on subdir with plain path: 1 Glob on subdir with long path prefix: 1 File delete with plain path: failed File delete with long path prefix: failed </pre> <pre> Tcl 8.5.17 Path length: 301 File mkdir with plain path: failed File mkdir with long path prefix File exists with plain path: 0 File exists with long path prefix: 1 Glob with plain path: failed Glob with long path prefix: 1 Glob -dir with plain path: failed Glob -dir with long path prefix: failed Glob on subdir with plain path: failed Glob on subdir with long path prefix: 1 File delete with plain path: failed File delete with long path prefix: failed </pre> As you can see, [glob //?/$path] works on both, but [glob $path] works only on the more recent version of Tcl. But neither [glob -dir //?/$path *] nor [glob -dir $path *] works at all, and that's what you need in order to traverse a directory hierarchy. - foundin changed to: "8.5.17"
- is_private changed to: "0"
- login: "john.j.seal"
- priority changed to: "5 Medium"
- private_contact changed to: "e1e289e81f931be9eb396cfee59849a6b74fd383"
- resolution changed to: "None"
- severity changed to: "Important"
- status changed to: "Open"
- submitter changed to: "john.j.seal"
- subsystem changed to: "36. Pathname Management"
- title changed to:
[glob -dir $path *] doesn't work for deeply nested paths
- type changed to: "Bug"