Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/glob?V=52
QUERY_STRINGV=52
CONTENT_TYPE
DOCUMENT_URI/revision/glob
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR172.70.130.155
REMOTE_PORT15718
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR3.141.47.221
HTTP_CF_RAY881595f75ea08753-ORD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_ACCEPT*/*
HTTP_USER_AGENTMozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; [email protected])
HTTP_CF_CONNECTING_IP3.141.47.221
HTTP_CDN_LOOPcloudflare
HTTP_CF_IPCOUNTRYUS

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit glob \nSupported\ ''switches''\ are:\nhttp://www.purl.org/tcl/home/man/tcl8.5/TclCmd/glob.htm\n\nThe\ \[\[glob\]\]\ command\ lists\ all\ the\ directory\ entries\ (files,\ directories,\ and\ links)\ whose\ names\ match\ a\ given\ pattern.\ If\ no\ files\ or\ directories\ were\ found,\ it\ throws\ an\ error,\ unless\ the\ '''-nocomplain'''\ switch\ is\ given.\ This\ models\ the\ behavior\ of\ \[Unix\]'s\ '''ls''':\n\ \$\ ls\ not_existing\n\ ls:\ not_existing:\ No\ such\ file\ or\ directory\n\ \$\ echo\ \$?\n\ 1\n\n\n\ \ \ \ :\ \ \ '''-directory'''\ ''directory''\n\ \ \ \ :\ \ \ '''-join'''\n\ \ \ \ :\ \ \ '''-nocomplain'''\n\ \ \ \ :\ \ \ '''-path'''\ ''pathPrefix''\n\ \ \ \ :\ \ \ '''-tails'''\n\ \ \ \ :\ \ \ '''-types'''\ ''typeList''\n\ \ \ \ :\ \ \ '''--'''\n\n\n<<discussion>>\n\nNote\ that\ one\ of\ glob's\ overlooked\ switches\ is\ the\ -type\ \[http://www.tcl.tk/man/tcl8.5/TclCmd/glob.htm#M10\]\ switch\ -\ with\ it,\ one\ can\ say,\ for\ instance,\n**\ Documentation\ **\n\ \ \ \ \ \ \ \ glob\ -type\ hidden\ *\n\ \ \ \ \[http://www.tcl.tk/man/tcl/TclCmd/glob.htm%|%official\ reference\]:\ \ \ \nand\ on\ unix,\ you\ will\ see\ all\ files\ beginning\ with\ a\ period\ (.),\ while\ on\ Windows\ and\ MacOS,\ you\ see\ truly\ ''hidden''\ files.\n\nConversely,\ it\ is\ worth\ knowing\ that\ under\ Windows\ \[\[glob\ *\]\]\ will\ return\ files\ named\ .*,\ as\ will\ \[\[glob\ *.*\]\].\ \ There's\ no\ single\ option\ to\ force\ Windows\ to\ follow\ the\ Unix\ convention\ (of\ .*\ files\ being\ hidden)\ but\ you\ can\ use\ the\ form\ ?*.*\ to\ force\ the\ Unix\ behaviour.\n----\n\nIt's\ usually\ best\ to\ build\ up\ the\ path\ with\ \[\[file\ join\]\]\ (see\ the\ \[file\]\ command\ for\ details),\ and\ then\ add\ a\ pattern\ after\ that.\ \ In\ Tcl\ 8.2\ to\ list\ all\ the\ entries\ in\ a\ given\ directory,\ for\ instance,\ one\ would\ use\n**\ Description\ **\n\ \ \ \[lsort\ \[glob\ \[file\ join\ \$dir\ \{\{.*,*\}\}\]\]\]\n'''`glob`'''\ lists\ all\ the\ directory\ entries\ whose\ names\ match\ a\ given\n(On\ Unix,\ Note\ that\ file\ names\ beginning\ with\ a\ period\ are\ hidden\ by\ default.\nThe\ pattern\ above\ expands\ these\ hidden\ files\ as\ well\ as\ the\ ordinary\nones).\n======none\n(\[NEM\]:\ This\ pattern\ fails,\ at\ least\ in\ 8.4.7\ and\ 8.5a3.\ It\ seems\ the\ \{a,b\}\ notation\ is\ for\ matching\ literal\ strings,\ not\ patterns.\ An\ alterative\ that\ appears\ to\ work\ is:\n\ \ \ \ \[lsort\ \[glob\ -dir\ \$dir\ *\ .*\]\]\n)\n\[PYK\]\ 2016-11-16:\ \ Except\ that\ it\ doesn't\ model\ the\ behaviour\ of\ ls\ in\ other\nHowever,\ this\ line\ actually\ has\ a\ bug\ in\ it:\ if\ \$dir\ contains\ characters\ which\ are\ glob-sensitive\ (any\ of\ those\ square/curly\ brackets,\ stars,\ question\ marks\ etc),\ the\ above\ example\ will\ fail.\ \ Therefore\ in\ Tcl\ 8.3\ or\ newer,\ you\ should\ ''always''\ use:\n\n\ \ \ \[lsort\ \[glob\ -dir\ \$dir\ \{.*,*\}\]\]\n\nwhich\ actually\ has\ the\ benefit\ of\ being\ clearer\ to\ read\ too!\ \ If\ you\ want\ to\ use\ this\ construction\ in\ older\ versions\ of\ Tcl,\ see\ \[glob\ forwards\ compatibility\]\ for\ a\ way\ to\ override\ the\ older\ \[\[glob\]\]\ command.\n======\nIndicate\ the\ end\ of\ the\ switch\ by\ \"--\"\ if\ your\ pattern\ contains\ \"-\".\nThere\ are\ cross-OS\ issues\ with\ this\ (in\ particular\ the\ handling\ of\ hidden\ files),\ \n\[LV\]\ Actually,\ you\ should\ ALWAYS\ use\ the\ ''--''\ \;\ there\ is\ no\ problem\ using\ it,\ and\ unless\ you\ are\ hardcoding\ literal\ arguments\ to\ glob\ you\ may\ accidentally\ get\ an\ argument\ beginning\ with\ a\ dash.\nTo\ get\ a\ list\ of\ all\ contents\ of\ a\ directory\ that\ aren't\ themselves\n----\nThe\ \[\[glob\]\]\ command\ can\ be\ used\ to\ simulate\ \[ls\ -l\ in\ Tcl\].\n\n----\n\nIn\ more\ recent\ versions\ of\ Tcl,\ glob\ even\ has\ a\ flag\ to\ specify\ whether\none\ wants\ just\ directories\ or\ files\ returned.\n----\n\[LV\]\ does\ anyone\ have\ some\ tcl\ code\ for\ handling\ negated\ patterns?\nThe\ \[ksh\]\ glob\ function\ allows\ me\ to\ do\ things\ like\ !(o*)\ or\ ab\[\[!b-z\]\ \nand\ I\ would\ like\ to\ be\ able\ to\ do\ similar\ things.\n----\n'''Stale\ links:'''\ ''glob''\ in\ older\ (pre\ Tcl\ 8.4a4)\ versions\ of\ Tcl\ has\ a\ funny\ behavior\ (seen\ on\ Solaris\ 5.5.1)\ with\ symbolic\ links\ that\ don't\ point\ to\ an\ existing\ file:\n\ %\ exec\ ln\ -s\ /does/not/exist\ stalelink\n\ %\ glob\ stalelink\n\ no\ files\ matched\ glob\ pattern\ \"stalelink\"\n\ %\ glob\ stalelink*\n\ stalelink\nIf\ the\ pattern\ is\ not\ wildcarded,\ it\ tries\ to\ follow\ the\ link\;\ otherwise\ it\ just\ returns\ the\ link's\ name\ itself.\ Hmm...\ (\[RS\])\n======\n----\n\n\[Tcl\ warts\]\ \ One\ might\ consider\ at\ least\ one\ of\ glob's\ behaviors\ as\na\ wart.\ \ glob\ uses\ the\ brace\ (\{\})\ characters\ as\ special\ notation,\ even\ though\ the\ tcl\ parser\ ALSO\ uses\ these\ characters.\ \ The\ result\ is\ that\ one\ needs\ to\ learn,\ from\ the\ beginning,\ that\ one\ needs\ to\ quote\ these\ characters\ when\ using\ them\ in\ glob\ arguments.\nglob\ also\ uses\ the\ \[\[\ and\ \]\]\ characters\ and\ those\ need\ quoted\ as\ well.\n\n'''EE:'''\ Actually,\ I'm\ of\ the\ opinion\ that\ one\ should\ always\ \"quote\"\ or\ \{brace\}\ arbitrary\ strings\ that\ are\ being\ used\ as\ command\ arguments.\n\n\[LV\]\ I\ agree.\ \ However,\ not\ everyone\ does\ so.\ \ It\ would\ look\ weird\nto\ say\ things\ like\ string\ \"length\"\ \$a\ or\ even\ somecmd\ \"-length\"\ \"60\"\ ,\nwouldn't\ it?\n\[PYK\]\ 2014-08-13:\ edited\ the\ example\ above\ to\ use\ `\[\[\[file\ tail\]\ \$item\]\]`\n'''EE:'''\ Yes\ it\ would,\ and\ I\ hadn't\ thought\ of\ that.\ But\ I\ draw\ a\ndistinction\ between\ the\ parts\ of\ the\ command\ itself,\ and\ the\ rest,\ which\nare\ the\ arguments.\ For\ your\ examples,\ '''\[string\]\ length'''\ is\ really\nthe\ command,\ and\ '''somecmd\ -length'''\ is\ really\ the\ command,\ and\ we\ngenerally\ don't\ quote\ the\ command.\ But\ I'll\ usually\ do\n'''string\ length\ \"\$a\"''',\ or\n'''somecmd\ -length\ \"60\"'''.\ And\ I'll\ ''certainly''\ do\n'''string\ compare\ \"\$stringone\"\ \"\$string2\"''',\ because\ it\ once\ took\ me\ two\ days\ to\ track\ down\ a\ bug\ caused\ by\ failing\ to\ put\ the\ arguments\ to\ a\ string\ compare\ into\ quotes.\n\n\[RS\]\ To\ the\ parser,\ the\ quotes\ just\ mean\ \"group\ me\"\ which\ is\ important\ if\ the\ quotes\ contain\ whitespace.\ If\ no\ substitutions\ are\ wanted,\ curly\ braces\ have\ the\ same\ effect,\ so\n\ \"a\ rose\"\ ==\ \{a\ rose\}\ !=\ a\ rose\nFor\ strings\ without\ whitespace,\ quotes\ are\ redundant,\ but\ may\ still\ serve\ a\ documentation\ purpose\ for\ the\ reader\ (e.g.\ in\ \[Salt\ and\ Sugar\],\ sugar\ arguments\ are\ quoted\ to\ express\ that\ they\ are\ just\ sugar).\n(Note\ that\ these\ are\ mutually\ exclusive.\ Also\ note\ that\ `-directory`\ can\ be\n'''EE:'''\ Is\ that\ completely\ true?\ The\ bug\ I\ speak\ of\ above\ was\ in\ a\ case\ where\ I\ was\ doing\ string\ manipulation\ on\ a\ variable\ which\ contained\ 32\ characters\ of\ purely\ digits,\ and\ it\ was\ erroring\ until\ I\ put\ the\ \$variable\ into\ quotes.\nLet's\ say\ I\ want\ to\ find\ all\ files\ in\ a\ directory,\ then\ I\ use\ (ignoring\ hidden\n'''\[LV\]'''\ Likewise,\ the\ point\ I\ was\ trying\ to\ make\ above\ was\ that\nfor\ glob\ (the\ subject\ of\ this\ page),\ one\ needs\ to\ do\ particularly\ special\ quoting\ to\ ensure\ that\ the\ parser\ doesn't\ touch\ the\ \{\ and\ \}\ncharacters,\ but\ lets\ them\ pass\ on\ to\ glob\ itself...\n\n'''Vince:'''\ fortunately\ with\ the\ use\ of\ '-dir'\ or\ '-path'\ flags\ to\ glob\ the\ need\ for\ quoting\ is\ pretty\ much\ gone\ in\ Tcl\ 8.3\ or\ newer.\n----\n\nAnyone\ want\ to\ talk\ about\ the\ use\ of\ ''-directory''\ vs\ ''-path''\ ?\n\nLet's\ say\ I\ want\ to\ find\ all\ files\ in\ a\ directory,\ then\ I\ use\ (ignoring\ hidden\ files\ for\ the\ moment)\n======\n\ \ \ \ glob\ -dir\ \$dir\ *\nNow,\ what\ I\ want\ all\ files\ in\ that\ directory\ whose\ names\ start\ with\ `\$nametail`\nNow,\ what\ I\ want\ all\ files\ in\ that\ directory\ whose\ names\ start\ with\ \$nametail\ (where\ I\ have\ no\ idea\ what\ characters\ are\ in\ \$nametail).\ \ I\ could\ try:\n======\n\ \ \ \ glob\ -dir\ \$dir\ \$\{nametail\}*\nbut\ that\ would\ fail\ (either\ with\ an\ error\ or\ not\ the\ expected\ result)\ if\nbut\ that\ would\ fail\ (either\ with\ an\ error\ or\ not\ the\ expected\ result)\ if\ nametail\ contains\ characters\ like\ \{\}.\ \ Therefore\ I\ must\ use\ ''-path'',\ like\ this:\n======\n\ \ \ \ glob\ -path\ \[file\ join\ \$dir\ \$nametail\]\ *\nOne\ thing\ to\ be\ aware\ of\ is\ that\ `-dir\ \{\}`\ is\ the\ same\ as\ `-dir\ .`.\ \ Hopefully\nAlso,\ when\ to\ use\ ''-join''?\n\nIf\ I\ want\ to\ find\ all\ *.tcl\ files\ in\ any\ subdirectory\ of\ a\ known\ directory,\ I\ could\ try\ this:\n======\n\ \ \ \ glob\ -dir\ \$dir\ */*.tcl\nbut\ that\ won't\ work\ on\ MacOS.\ \ So,\ use\ `-join`:\nbut\ that\ won't\ work\ on\ MacOS.\ \ So,\ use\ -join:\n======\n\ \ \ \ glob\ -join\ -dir\ \$dir\ *\ *.tcl\n\nHope\ that\ helps!\n**\ Trailing\ `/`\ **\n----\n'''Recursive\ glob:'''\ This\ lightly\ tested\ procedure\ follows\ subdirectories\ (not\ sure\ what\ happens\ with\ links)\ and\ returns\ all\ non-directories\ in\ alphabetic\ order:\n\ proc\ glob-r\ \{\{dir\ .\}\}\ \{\n\ \ \ \ foreach\ i\ \[lsort\ \[glob\ -nocomplain\ -dir\ \$dir\ *\]\]\ \{\n\ \ \ \ \ \ \ \ if\ \{\[file\ type\ \$i\]\ eq\ \{directory\}\}\ \{\n\ \ \ \ \ \ \ \ if\ \{\[file\ type\ \$i\]==\"directory\"\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ eval\ lappend\ \ res\ \[glob-r\ \$i\]\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ res\ \$i\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ return\ \$res\n\ \ \ \ set\ res\n\ \}\ \;#\ RS\n(Invocation\ without\ arguments\ verified\ works\ with\ 8.6.)\n\[JH\]\ May\ 16th\ 2006:\ With\ this\ variant\ that\ allows\ for\ optional\ patterns\ of\ interest,\ like\ '''glob-r\ C:/Tcl\ *.gif\ *.ps''':\n======\n\ proc\ glob-r\ \{\{dir\ .\}\ args\}\ \{\n\ \ \ \ \ set\ res\ \{\}\n\ \ \ \ \ foreach\ i\ \[lsort\ \[glob\ -nocomplain\ -dir\ \$dir\ *\]\]\ \{\n\ \ \ \ \ \ \ \ \ if\ \{\[file\ isdirectory\ \$i\]\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ eval\ \[list\ lappend\ res\]\ \[eval\ \[linsert\ \$args\ 0\ glob-r\ \$i\]\]\n\ \ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ if\ \{\[llength\ \$args\]\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ foreach\ arg\ \$args\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ if\ \{\[string\ match\ \$arg\ \$i\]\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lappend\ res\ \$i\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ break\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lappend\ res\ \$i\n\ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \}\n\ \ \ \ \ return\ \$res\n\ \}\ \;#\ JH\n\n\[MG\]\ May\ 20th\ 2004\ -\ I\ couldn't\ get\ the\ above\ code\ to\ work,\ so\ wrote\ my\ own\ version\ of\ it.\ The\ only\ oddity\ about\ it\ is\ that\ paths\ (sometimes)\ start\ '././',\ rather\ than\ just\ './'\ -\ I\ really\ don't\ know\ why.\ But\ using\ \[\[file\ exists\]\]\ on\ those\ files\ still\ works,\ so\ it\ doesn't\ really\ seem\ to\ matter.\ (It\ also\ uses\ \[\[info\ level\ 0\]\]\ to\ find\ out\ it's\ own\ name\ when\ it\ calls\ itself\ recursively\;\ this\ is,\ simply,\ because\ I\ just\ found\ out\ how\ you\ do\ that\ :)\ Replacing\ ''\[\[lindex\ \[\[info\ level\ 0\]\]\ 0\]\]''\ with\ ''globRec''\ (or\ whatever\ you\ call\ the\ procedure)\ will\ speed\ it\ up\ a\ fair\ bit.\ ''Changed\ quickly\ to\ add\ --\ into\ the\ \[\[glob\]\]\ calls,\ so\ \$dir\ can't\ be\ mistaken\ as\ a\ switch,\ as\ suggested\ above''.\ Takes\ an\ optional\ second\ argument\ to\ specify\ which\ types\ of\ file\ to\ \[\[glob\]\]\ for\;\ by\ default,\ all\ mentioned\ on\ the\ manpage\ apart\ from\ directories.\n\n\ proc\ globRec\ \{\{dir\ .\}\ \{types\ \{b\ c\ f\ l\ p\ s\}\}\}\ \{\n\ \ \ set\ files\ \[glob\ -nocomplain\ -types\ \$types\ -dir\ \$dir\ --\ *\]\n\ \ \ foreach\ x\ \[glob\ -nocomplain\ -types\ \{d\}\ -dir\ \$dir\ --\ *\]\ \{\n\ \ \ \ \ \ \ \ \ \ \ set\ files\ \[concat\ \$files\ \[\[lindex\ \[info\ level\ 0\]\ 0\]\ \[file\ join\ \$dir\ \$x\]\]\]\n\ \ \ \ \ \ \ \ \ \ \}\n\ \ \ return\ \[lsort\ \$files\]\;\n\ \}\;#\ globRec\n\ \nTC\ 23\ Nov\ 2004\ -\ I\ couldn't\ get\ either\ of\ the\ above\ functions\ to\ do\ what\ I\ wanted,\ which\ was\ to\ recursively\ list\ all\ directories\ and\ use\ a\ filespec.\ \ My\ TCL\ hack\ (lightly\ tested\ on\ 8.3\ and\ 8.5)\ of\ \[MG\]'s\ code,\ which\ seems\ to\ do\ all\ his\ was\ intended\ to\ do\ also.\ \ Modified\ to\ also\ eliminate\ leading\ ./s.\ Modified\ to\ support\ filenames\ with\ spaces\ in\ them.\nNote:\ you\ may\ need\ to\ replace\ `\[file\ join\]\ \$dir\ \$x`\ with\ simply\ `\$x`.\ I\ had\ to.\nNote:\ you\ may\ need\ to\ replace\ \[file\ join\ \$dir\ \$x\]\ with\ simply\ \$x.\ I\ had\ to.\n======\n\ proc\ globRec\ \{\{dir\ .\}\ \{filespec\ \"*\"\}\ \{types\ \{b\ c\ f\ l\ p\ s\}\}\}\ \{\n\ \ set\ files\ \[glob\ -nocomplain\ -types\ \$types\ -dir\ \$dir\ --\ \$filespec\]\n\ \ foreach\ x\ \[glob\ -nocomplain\ -types\ \{d\}\ -dir\ \$dir\ --\ *\]\ \{\n\ \ \ set\ files\ \[concat\ \$files\ \[globRec\ \[file\ join\ \$dir\ \$x\]\ \$filespec\ \$types\]\]\n\ \ \}\n\ \ set\ filelist\ \{\}\n\ \ foreach\ x\ \$files\ \{\n\ \ \ while\ \{\[string\ range\ \$x\ 0\ 1\]==\"./\"\}\ \{\n\ \ \ \ regsub\ ./\ \$x\ \"\"\ x\n\ \ \ \}\n\ \ \ lappend\ filelist\ \$x\n\ \ \}\n\ \ return\ \$filelist\;\n\ \}\;#\ globRec\n\n\[jys\]\ –\ I\ wanted\ a\ recursive\ glob\ that\ would\ take\ the\ same\ options\ as\ glob,\ so\ I\ wrote\ this\ wrapper.\ I\ don't\ know\ if\ it\ works\ 100%\ with\ all\ options\ though,\ and\ it\ currently\ gets\ tripped\ up\ by\ glob\ spitting\ the\ dummy\ when\ it\ can't\ look\ inside\ a\ directory\ (generally\ 'cause\ of\ permissions).\n\ proc\ rglob\ \{args\}\ \{\n\ \ \ \ \ \ \ \ \ #\ This\ code\ requires\ -join\ and\ -nocomplain.\ We\ also\ remove\ the\ -types\ option,\ and\ then\ manually\ apply\ a\ filter\ at\ the\ end.\n\ \ \ \ \ \ \ \ \ set\ args\ \[linsert\ \$args\ 0\ -nocomplain\ -join\]\n\ \ \ \ \ \ \ \ \ if\ \{\[set\ types_index\ \[lsearch\ -exact\ \$args\ -types\]\]\ !=\ -1\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ types\ \[lindex\ \$args\ \[expr\ \{\$types_index+1\}\]\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ args\ \[lreplace\ \$args\ \$types_index\ \[expr\ \{\$types_index+1\}\]\]\n\ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ #\ Get\ inital\ matches.\n\ \ \ \ \ \ \ \ \ set\ matches\ \[glob\ \{*\}\$args\]\n\ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ #\ Keep\ adding\ *\ wildcards\ to\ search\ through\ subdirectories\ until\ there\ are\ no\ more\ levels\ of\ directories\ to\ search.\n\ \ \ \ \ \ \ \ \ while\ \{\[llength\ \[glob\ -types\ d\ \{*\}\[lreplace\ \$args\ end\ end\ *\]\]\]\ >\ 0\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ args\ \[linsert\ \$args\ end-1\ *\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lappend\ matches\ \{*\}\[glob\ \{*\}\$args\]\n\ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ #\ Filter\ matches\ with\ -types\ option.\n\ \ \ \ \ \ \ \ \ if\ \{\[info\ exists\ types\]\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ matches\ \[glob\ -nocomplain\ -types\ \$types\ \{*\}\$matches\]\}\n\ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ return\ \$matches\n\ \}\n----\n\[ES\]:\ '''findfile:'''\ This\ procedure\ was\ inspired\ by\ glob-r\ above\ and\ is\ customized\ to\ quickly\ find\ the\ first\ instance\ of\ a\ file\ in\ a\ given\ path.\n\n\ proc\ findfile\ \{\ dir\ fname\ \}\ \{\n\ \ \ \ \ \ \ \ \[llength\ \[set\ x\ \[glob\ -nocomplain\ -dir\ \$dir\ \$fname\]\]\]\n\ \ \ \ \}\ \{\n\ \ \ \ \ \ \ \ return\ \[lindex\ \$x\ 0\]\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ foreach\ i\ \[glob\ -nocomplain\ -type\ d\ -dir\ \$dir\ *\]\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$i\ !=\ \$dir\ &&\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[llength\ \[set\ x\ \[findfile\ \$i\ \$fname\]\]\]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return\ \$x\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\}\n\ \}\n(Verified\ works\ with\ 8.6.)\n----\n\[MSW\]:\ \[pathentry\]:\ Entry\ widget/binding\ set\ using\ glob\ to\ offer\ quick\ auto-completion\ of\ paths\n----\n\[GPS\]:\ In\ the\ Tcl'ers\ chat\ this\ elegant\ solution\ was\ created\ by\ \[DKF\]:\n\n\ proc\ *\ args\ \{glob\ -nocomplain\ *\[join\ \$args\ \{\}\]\}\n\n(\[CMCc\]:\ Now\ try\ the\ same\ kind\ of\ composition\ and\ extension\ under\ /bin/sh\ :)\n\n\[MJ\]\ -\ Shouldn't\ this\ be:\n\ \n\ proc\ *\ args\ \{glob\ -nocomplain\ *\\\{\[join\ \$args\ ,\]\\\}\}\n\nBecause\ \[DKF\]'s\ version\ doesn't\ do\ what\ I\ expect\ it\ to\ do\ with\ multiple\ args\ (maybe\ my\ expectation\ is\ wrong)\ \n\n----\n\[EB\]:\ The\ \[changes\ in\ Tcl/Tk\ 8.4.9\]\ shows\ that\ ''tilde\ paths\ are\ not\ returned\ specially\ by\ \[glob\]'',\ but\ shouldn't\nthat\ have\ been\ done\ to\ avoid\ a\ security\ problem\ with\ ~\ expansion\ ?\ e.g:\n\n\ foreach\ file\ \[glob\ \"*\"\]\ \{\n\ \ \ file\ delete\ -force\ \$file\n\ \}\n\nwhere\ \[glob\]\ returns\ a\ file\ beginning\ with\ a\ ~\ ?\n\n\[Vince\]\ writes:\ for\ historical\ reasons\ the\ code\ above\ is\ considered\ wrong/buggy.\ \ You\ should\ write\ ''file\ delete\ -force\ ./\$file''.\ \ This\ is\ perhaps\ something\ that\ should\ be\ changed\ in\ the\ future,\ but\ it\ might\ well\ break\ some\ old\ code.\ \ There\ is\ even\ a\ bug\ report\ or\ patch\ somewhere\ on\ sf\ about\ this,\ I\ think\ (probably\ closed\ now).\n\n----\nSee\ also\ here:\ \[Matthias\ Hoffmann\ -\ Tcl-Code-Snippets\]!\n----\n\nHere\ is\ a\ proc\ that\ will\ list\ the\ directory\ tree\ under\ any\ given\ root,\ giving\ the\ full\ path\ name\ of\ all\ descendants.\ It\ embeds\ glob\ in\ a\ recursive\ call\;\ a\ directory\ with\ no\ descendants\ is\ the\ base\ case.\n======\n\ proc\ listTree\ \{rootdir_\}\ \{\n\ #\ Precondition:\ rootdir_\ is\ valid\ path\ \n\ \ \ \ \ set\ currentnodes\ \[glob\ -nocomplain\ -directory\ \$rootdir_\ -types\ d\ *\]\n\ \ \ \ \ if\ \{\[llength\ \$currentnodes\]\ <=\ 0\}\ \{\n\ \ \ \ \ #\ Base\ case:\ the\ current\ dir\ is\ a\ leaf,\ write\ out\ the\ leaf\ \n\ \ \ \ \ \ \ \ \ puts\ \$rootdir_\n\ \ \ \ \ \ \ \ \ return\n\ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ #\ write\ out\ the\ current\ node\ \n\ \ \ \ \ \ \ \ return\n\ \ \ \ \ #\ Recurse\ over\ all\ dirs\ at\ this\ level\n\ \ \ \ \ \ \ \ \ foreach\ node\ \$currentnodes\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ listTree\ \$node\n\ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \}\n\ \}\nlistTree\ \[pwd\]\n\ listTree\ \[pwd\]\n(Verified\ works\ with\ 8.6\ (and\ is\ surprisingly\ quick).)\nThat\ this\ isn't\ a\ Tcl\ built-in\ (or\ if\ it\ is,\ why\ is\ it\ is\ such\ a\ well-kept\ secret)\ strikes\ me\ as\ odd.\ \nI\ remember\ reading\ something\ about\ a\ pre-defined\ limit\ on\ depth\ of\ recursion\ in\nI\ remember\ reading\ something\ about\ a\ pre-defined\ limit\ on\ depth\ of\ recursion\ in\ Tcl,\ \nso\ this\ code\ is\ not\ guaranteed\ for\ arbitrarily\ deep\ file\ structures.\nBob\n\n\n\n\[kostix\]\ (04-Sep-07)\ notes\ that\ there's\ one\ trick\ with\ '''glob'''\ on\ Windows:\n\ glob\ -dir\ c:\ *\nwill\ list\ contents\ of\ ''the\ current\ working\ directory\ on\ drive\ C:,''\ not\ the\ contents\ of\ the\ root\ folder\ on\ that\ drive.\n======\n\n\ glob\ -dir\ c:/\ *\n======\nThe\ described\ behaviour\ is\ consistent\ with\ what\ is\ seen\ in\ '''cmd.exe'''\ command\ shell.\nThe\ described\ behaviour\ is\ consistent\ with\ what\ is\ seen\ in\ '''cmd.exe'''\n\n\[Zipguy\]\ 2013-02-07\ -\ Thanks\ \[kostix\]\ for\ pointing\ this\ out.\ \ I\ do\ use\ windows\n----\n\[Sarnold\]:\ Sometimes\ \[glob\]-like\ patterns\ are\ expected\ to\ be\ passed\ to\ some\ commands.\ This\ may\ lead\ to\ bugs,\ for\ example,\nin\ \[http://groups.google.com/group/comp.lang.tcl/browse_thread/thread/a2021acab428e198/b79eadada5bc5f3b#b79eadada5bc5f3b\]:\n**\ Stale\ links\ **\n\ set\ bar\ \{x\[y\]\}\n\ set\ foo(\$bar)\ yes\n\ array\ unset\ foo\ \$bar\n\ parray\ foo\ =>\ foo(x\[y\])\ still\ exists\nIf\ the\ pattern\ is\ not\ wildcarded,\ it\ tries\ to\ follow\ the\ link\;\ otherwise\ it\nWhat's\ the\ cure,\ Doctor?\ '''Unglob\ it!'''\n\n\ proc\ unglob\ \{x\}\ \{\n\ \ \ \ \ string\ map\ \{*\ \\\\*\ ?\ \\\\?\ \[\ \\\\\[\ \]\ \\\\\]\}\ \$x\n\ \}\n----\nIn\ a\ recent\ email\ thread\ on\ the\ \[Modules\]\ mailing\ list,\ a\ developer\ reported\ a\ change\ he\ found\ when\ beginning\ to\ use\ Tcl\ 8.5:\n\[Vince\]\ writes:\ for\ historical\ reasons\ the\ code\ above\ is\ considered\n===\n\$\ tclsh8.4\n%\ glob\ /home/\n/home\n%\ glob\ /home\n/home\n^D\n\$\ tclsh8.5\n%\ glob\ /home/\n/home/\n%\ glob\ /home\n/home\n^D\n\n===\nTurns\ out\ that\ the\ modules\ package\ was\ dependant\ on\ having\ the\ path\ returned\ without\ the\ trailing\ '''/''',\ and\ when\ 8.5\ started\ returning\ some\ paths\ with\ the\ slash,\ certain\ behaviors\ changed.\n\nFrom\ a\ purely\ technical\ point\ of\ view,\ the\ two\ forms\ of\ the\ name\ are\ considered\ equivalent\ by\ the\ operating\ systems\ with\ which\ I\ am\ familar\ (Ultrix,\ Solaris,\ etc.).\ I\ don't\ know\ if\ there\ are\ differences\ for\ variants\ or\ not.\ \n\n<<discussion>>\n regexp2} CALL {my render glob \nSupported\ ''switches''\ are:\nhttp://www.purl.org/tcl/home/man/tcl8.5/TclCmd/glob.htm\n\nThe\ \[\[glob\]\]\ command\ lists\ all\ the\ directory\ entries\ (files,\ directories,\ and\ links)\ whose\ names\ match\ a\ given\ pattern.\ If\ no\ files\ or\ directories\ were\ found,\ it\ throws\ an\ error,\ unless\ the\ '''-nocomplain'''\ switch\ is\ given.\ This\ models\ the\ behavior\ of\ \[Unix\]'s\ '''ls''':\n\ \$\ ls\ not_existing\n\ ls:\ not_existing:\ No\ such\ file\ or\ directory\n\ \$\ echo\ \$?\n\ 1\n\n\n\ \ \ \ :\ \ \ '''-directory'''\ ''directory''\n\ \ \ \ :\ \ \ '''-join'''\n\ \ \ \ :\ \ \ '''-nocomplain'''\n\ \ \ \ :\ \ \ '''-path'''\ ''pathPrefix''\n\ \ \ \ :\ \ \ '''-tails'''\n\ \ \ \ :\ \ \ '''-types'''\ ''typeList''\n\ \ \ \ :\ \ \ '''--'''\n\n\n<<discussion>>\n\nNote\ that\ one\ of\ glob's\ overlooked\ switches\ is\ the\ -type\ \[http://www.tcl.tk/man/tcl8.5/TclCmd/glob.htm#M10\]\ switch\ -\ with\ it,\ one\ can\ say,\ for\ instance,\n**\ Documentation\ **\n\ \ \ \ \ \ \ \ glob\ -type\ hidden\ *\n\ \ \ \ \[http://www.tcl.tk/man/tcl/TclCmd/glob.htm%|%official\ reference\]:\ \ \ \nand\ on\ unix,\ you\ will\ see\ all\ files\ beginning\ with\ a\ period\ (.),\ while\ on\ Windows\ and\ MacOS,\ you\ see\ truly\ ''hidden''\ files.\n\nConversely,\ it\ is\ worth\ knowing\ that\ under\ Windows\ \[\[glob\ *\]\]\ will\ return\ files\ named\ .*,\ as\ will\ \[\[glob\ *.*\]\].\ \ There's\ no\ single\ option\ to\ force\ Windows\ to\ follow\ the\ Unix\ convention\ (of\ .*\ files\ being\ hidden)\ but\ you\ can\ use\ the\ form\ ?*.*\ to\ force\ the\ Unix\ behaviour.\n----\n\nIt's\ usually\ best\ to\ build\ up\ the\ path\ with\ \[\[file\ join\]\]\ (see\ the\ \[file\]\ command\ for\ details),\ and\ then\ add\ a\ pattern\ after\ that.\ \ In\ Tcl\ 8.2\ to\ list\ all\ the\ entries\ in\ a\ given\ directory,\ for\ instance,\ one\ would\ use\n**\ Description\ **\n\ \ \ \[lsort\ \[glob\ \[file\ join\ \$dir\ \{\{.*,*\}\}\]\]\]\n'''`glob`'''\ lists\ all\ the\ directory\ entries\ whose\ names\ match\ a\ given\n(On\ Unix,\ Note\ that\ file\ names\ beginning\ with\ a\ period\ are\ hidden\ by\ default.\nThe\ pattern\ above\ expands\ these\ hidden\ files\ as\ well\ as\ the\ ordinary\nones).\n======none\n(\[NEM\]:\ This\ pattern\ fails,\ at\ least\ in\ 8.4.7\ and\ 8.5a3.\ It\ seems\ the\ \{a,b\}\ notation\ is\ for\ matching\ literal\ strings,\ not\ patterns.\ An\ alterative\ that\ appears\ to\ work\ is:\n\ \ \ \ \[lsort\ \[glob\ -dir\ \$dir\ *\ .*\]\]\n)\n\[PYK\]\ 2016-11-16:\ \ Except\ that\ it\ doesn't\ model\ the\ behaviour\ of\ ls\ in\ other\nHowever,\ this\ line\ actually\ has\ a\ bug\ in\ it:\ if\ \$dir\ contains\ characters\ which\ are\ glob-sensitive\ (any\ of\ those\ square/curly\ brackets,\ stars,\ question\ marks\ etc),\ the\ above\ example\ will\ fail.\ \ Therefore\ in\ Tcl\ 8.3\ or\ newer,\ you\ should\ ''always''\ use:\n\n\ \ \ \[lsort\ \[glob\ -dir\ \$dir\ \{.*,*\}\]\]\n\nwhich\ actually\ has\ the\ benefit\ of\ being\ clearer\ to\ read\ too!\ \ If\ you\ want\ to\ use\ this\ construction\ in\ older\ versions\ of\ Tcl,\ see\ \[glob\ forwards\ compatibility\]\ for\ a\ way\ to\ override\ the\ older\ \[\[glob\]\]\ command.\n======\nIndicate\ the\ end\ of\ the\ switch\ by\ \"--\"\ if\ your\ pattern\ contains\ \"-\".\nThere\ are\ cross-OS\ issues\ with\ this\ (in\ particular\ the\ handling\ of\ hidden\ files),\ \n\[LV\]\ Actually,\ you\ should\ ALWAYS\ use\ the\ ''--''\ \;\ there\ is\ no\ problem\ using\ it,\ and\ unless\ you\ are\ hardcoding\ literal\ arguments\ to\ glob\ you\ may\ accidentally\ get\ an\ argument\ beginning\ with\ a\ dash.\nTo\ get\ a\ list\ of\ all\ contents\ of\ a\ directory\ that\ aren't\ themselves\n----\nThe\ \[\[glob\]\]\ command\ can\ be\ used\ to\ simulate\ \[ls\ -l\ in\ Tcl\].\n\n----\n\nIn\ more\ recent\ versions\ of\ Tcl,\ glob\ even\ has\ a\ flag\ to\ specify\ whether\none\ wants\ just\ directories\ or\ files\ returned.\n----\n\[LV\]\ does\ anyone\ have\ some\ tcl\ code\ for\ handling\ negated\ patterns?\nThe\ \[ksh\]\ glob\ function\ allows\ me\ to\ do\ things\ like\ !(o*)\ or\ ab\[\[!b-z\]\ \nand\ I\ would\ like\ to\ be\ able\ to\ do\ similar\ things.\n----\n'''Stale\ links:'''\ ''glob''\ in\ older\ (pre\ Tcl\ 8.4a4)\ versions\ of\ Tcl\ has\ a\ funny\ behavior\ (seen\ on\ Solaris\ 5.5.1)\ with\ symbolic\ links\ that\ don't\ point\ to\ an\ existing\ file:\n\ %\ exec\ ln\ -s\ /does/not/exist\ stalelink\n\ %\ glob\ stalelink\n\ no\ files\ matched\ glob\ pattern\ \"stalelink\"\n\ %\ glob\ stalelink*\n\ stalelink\nIf\ the\ pattern\ is\ not\ wildcarded,\ it\ tries\ to\ follow\ the\ link\;\ otherwise\ it\ just\ returns\ the\ link's\ name\ itself.\ Hmm...\ (\[RS\])\n======\n----\n\n\[Tcl\ warts\]\ \ One\ might\ consider\ at\ least\ one\ of\ glob's\ behaviors\ as\na\ wart.\ \ glob\ uses\ the\ brace\ (\{\})\ characters\ as\ special\ notation,\ even\ though\ the\ tcl\ parser\ ALSO\ uses\ these\ characters.\ \ The\ result\ is\ that\ one\ needs\ to\ learn,\ from\ the\ beginning,\ that\ one\ needs\ to\ quote\ these\ characters\ when\ using\ them\ in\ glob\ arguments.\nglob\ also\ uses\ the\ \[\[\ and\ \]\]\ characters\ and\ those\ need\ quoted\ as\ well.\n\n'''EE:'''\ Actually,\ I'm\ of\ the\ opinion\ that\ one\ should\ always\ \"quote\"\ or\ \{brace\}\ arbitrary\ strings\ that\ are\ being\ used\ as\ command\ arguments.\n\n\[LV\]\ I\ agree.\ \ However,\ not\ everyone\ does\ so.\ \ It\ would\ look\ weird\nto\ say\ things\ like\ string\ \"length\"\ \$a\ or\ even\ somecmd\ \"-length\"\ \"60\"\ ,\nwouldn't\ it?\n\[PYK\]\ 2014-08-13:\ edited\ the\ example\ above\ to\ use\ `\[\[\[file\ tail\]\ \$item\]\]`\n'''EE:'''\ Yes\ it\ would,\ and\ I\ hadn't\ thought\ of\ that.\ But\ I\ draw\ a\ndistinction\ between\ the\ parts\ of\ the\ command\ itself,\ and\ the\ rest,\ which\nare\ the\ arguments.\ For\ your\ examples,\ '''\[string\]\ length'''\ is\ really\nthe\ command,\ and\ '''somecmd\ -length'''\ is\ really\ the\ command,\ and\ we\ngenerally\ don't\ quote\ the\ command.\ But\ I'll\ usually\ do\n'''string\ length\ \"\$a\"''',\ or\n'''somecmd\ -length\ \"60\"'''.\ And\ I'll\ ''certainly''\ do\n'''string\ compare\ \"\$stringone\"\ \"\$string2\"''',\ because\ it\ once\ took\ me\ two\ days\ to\ track\ down\ a\ bug\ caused\ by\ failing\ to\ put\ the\ arguments\ to\ a\ string\ compare\ into\ quotes.\n\n\[RS\]\ To\ the\ parser,\ the\ quotes\ just\ mean\ \"group\ me\"\ which\ is\ important\ if\ the\ quotes\ contain\ whitespace.\ If\ no\ substitutions\ are\ wanted,\ curly\ braces\ have\ the\ same\ effect,\ so\n\ \"a\ rose\"\ ==\ \{a\ rose\}\ !=\ a\ rose\nFor\ strings\ without\ whitespace,\ quotes\ are\ redundant,\ but\ may\ still\ serve\ a\ documentation\ purpose\ for\ the\ reader\ (e.g.\ in\ \[Salt\ and\ Sugar\],\ sugar\ arguments\ are\ quoted\ to\ express\ that\ they\ are\ just\ sugar).\n(Note\ that\ these\ are\ mutually\ exclusive.\ Also\ note\ that\ `-directory`\ can\ be\n'''EE:'''\ Is\ that\ completely\ true?\ The\ bug\ I\ speak\ of\ above\ was\ in\ a\ case\ where\ I\ was\ doing\ string\ manipulation\ on\ a\ variable\ which\ contained\ 32\ characters\ of\ purely\ digits,\ and\ it\ was\ erroring\ until\ I\ put\ the\ \$variable\ into\ quotes.\nLet's\ say\ I\ want\ to\ find\ all\ files\ in\ a\ directory,\ then\ I\ use\ (ignoring\ hidden\n'''\[LV\]'''\ Likewise,\ the\ point\ I\ was\ trying\ to\ make\ above\ was\ that\nfor\ glob\ (the\ subject\ of\ this\ page),\ one\ needs\ to\ do\ particularly\ special\ quoting\ to\ ensure\ that\ the\ parser\ doesn't\ touch\ the\ \{\ and\ \}\ncharacters,\ but\ lets\ them\ pass\ on\ to\ glob\ itself...\n\n'''Vince:'''\ fortunately\ with\ the\ use\ of\ '-dir'\ or\ '-path'\ flags\ to\ glob\ the\ need\ for\ quoting\ is\ pretty\ much\ gone\ in\ Tcl\ 8.3\ or\ newer.\n----\n\nAnyone\ want\ to\ talk\ about\ the\ use\ of\ ''-directory''\ vs\ ''-path''\ ?\n\nLet's\ say\ I\ want\ to\ find\ all\ files\ in\ a\ directory,\ then\ I\ use\ (ignoring\ hidden\ files\ for\ the\ moment)\n======\n\ \ \ \ glob\ -dir\ \$dir\ *\nNow,\ what\ I\ want\ all\ files\ in\ that\ directory\ whose\ names\ start\ with\ `\$nametail`\nNow,\ what\ I\ want\ all\ files\ in\ that\ directory\ whose\ names\ start\ with\ \$nametail\ (where\ I\ have\ no\ idea\ what\ characters\ are\ in\ \$nametail).\ \ I\ could\ try:\n======\n\ \ \ \ glob\ -dir\ \$dir\ \$\{nametail\}*\nbut\ that\ would\ fail\ (either\ with\ an\ error\ or\ not\ the\ expected\ result)\ if\nbut\ that\ would\ fail\ (either\ with\ an\ error\ or\ not\ the\ expected\ result)\ if\ nametail\ contains\ characters\ like\ \{\}.\ \ Therefore\ I\ must\ use\ ''-path'',\ like\ this:\n======\n\ \ \ \ glob\ -path\ \[file\ join\ \$dir\ \$nametail\]\ *\nOne\ thing\ to\ be\ aware\ of\ is\ that\ `-dir\ \{\}`\ is\ the\ same\ as\ `-dir\ .`.\ \ Hopefully\nAlso,\ when\ to\ use\ ''-join''?\n\nIf\ I\ want\ to\ find\ all\ *.tcl\ files\ in\ any\ subdirectory\ of\ a\ known\ directory,\ I\ could\ try\ this:\n======\n\ \ \ \ glob\ -dir\ \$dir\ */*.tcl\nbut\ that\ won't\ work\ on\ MacOS.\ \ So,\ use\ `-join`:\nbut\ that\ won't\ work\ on\ MacOS.\ \ So,\ use\ -join:\n======\n\ \ \ \ glob\ -join\ -dir\ \$dir\ *\ *.tcl\n\nHope\ that\ helps!\n**\ Trailing\ `/`\ **\n----\n'''Recursive\ glob:'''\ This\ lightly\ tested\ procedure\ follows\ subdirectories\ (not\ sure\ what\ happens\ with\ links)\ and\ returns\ all\ non-directories\ in\ alphabetic\ order:\n\ proc\ glob-r\ \{\{dir\ .\}\}\ \{\n\ \ \ \ foreach\ i\ \[lsort\ \[glob\ -nocomplain\ -dir\ \$dir\ *\]\]\ \{\n\ \ \ \ \ \ \ \ if\ \{\[file\ type\ \$i\]\ eq\ \{directory\}\}\ \{\n\ \ \ \ \ \ \ \ if\ \{\[file\ type\ \$i\]==\"directory\"\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ eval\ lappend\ \ res\ \[glob-r\ \$i\]\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ res\ \$i\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ return\ \$res\n\ \ \ \ set\ res\n\ \}\ \;#\ RS\n(Invocation\ without\ arguments\ verified\ works\ with\ 8.6.)\n\[JH\]\ May\ 16th\ 2006:\ With\ this\ variant\ that\ allows\ for\ optional\ patterns\ of\ interest,\ like\ '''glob-r\ C:/Tcl\ *.gif\ *.ps''':\n======\n\ proc\ glob-r\ \{\{dir\ .\}\ args\}\ \{\n\ \ \ \ \ set\ res\ \{\}\n\ \ \ \ \ foreach\ i\ \[lsort\ \[glob\ -nocomplain\ -dir\ \$dir\ *\]\]\ \{\n\ \ \ \ \ \ \ \ \ if\ \{\[file\ isdirectory\ \$i\]\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ eval\ \[list\ lappend\ res\]\ \[eval\ \[linsert\ \$args\ 0\ glob-r\ \$i\]\]\n\ \ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ if\ \{\[llength\ \$args\]\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ foreach\ arg\ \$args\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ if\ \{\[string\ match\ \$arg\ \$i\]\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lappend\ res\ \$i\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ break\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lappend\ res\ \$i\n\ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \}\n\ \ \ \ \ return\ \$res\n\ \}\ \;#\ JH\n\n\[MG\]\ May\ 20th\ 2004\ -\ I\ couldn't\ get\ the\ above\ code\ to\ work,\ so\ wrote\ my\ own\ version\ of\ it.\ The\ only\ oddity\ about\ it\ is\ that\ paths\ (sometimes)\ start\ '././',\ rather\ than\ just\ './'\ -\ I\ really\ don't\ know\ why.\ But\ using\ \[\[file\ exists\]\]\ on\ those\ files\ still\ works,\ so\ it\ doesn't\ really\ seem\ to\ matter.\ (It\ also\ uses\ \[\[info\ level\ 0\]\]\ to\ find\ out\ it's\ own\ name\ when\ it\ calls\ itself\ recursively\;\ this\ is,\ simply,\ because\ I\ just\ found\ out\ how\ you\ do\ that\ :)\ Replacing\ ''\[\[lindex\ \[\[info\ level\ 0\]\]\ 0\]\]''\ with\ ''globRec''\ (or\ whatever\ you\ call\ the\ procedure)\ will\ speed\ it\ up\ a\ fair\ bit.\ ''Changed\ quickly\ to\ add\ --\ into\ the\ \[\[glob\]\]\ calls,\ so\ \$dir\ can't\ be\ mistaken\ as\ a\ switch,\ as\ suggested\ above''.\ Takes\ an\ optional\ second\ argument\ to\ specify\ which\ types\ of\ file\ to\ \[\[glob\]\]\ for\;\ by\ default,\ all\ mentioned\ on\ the\ manpage\ apart\ from\ directories.\n\n\ proc\ globRec\ \{\{dir\ .\}\ \{types\ \{b\ c\ f\ l\ p\ s\}\}\}\ \{\n\ \ \ set\ files\ \[glob\ -nocomplain\ -types\ \$types\ -dir\ \$dir\ --\ *\]\n\ \ \ foreach\ x\ \[glob\ -nocomplain\ -types\ \{d\}\ -dir\ \$dir\ --\ *\]\ \{\n\ \ \ \ \ \ \ \ \ \ \ set\ files\ \[concat\ \$files\ \[\[lindex\ \[info\ level\ 0\]\ 0\]\ \[file\ join\ \$dir\ \$x\]\]\]\n\ \ \ \ \ \ \ \ \ \ \}\n\ \ \ return\ \[lsort\ \$files\]\;\n\ \}\;#\ globRec\n\ \nTC\ 23\ Nov\ 2004\ -\ I\ couldn't\ get\ either\ of\ the\ above\ functions\ to\ do\ what\ I\ wanted,\ which\ was\ to\ recursively\ list\ all\ directories\ and\ use\ a\ filespec.\ \ My\ TCL\ hack\ (lightly\ tested\ on\ 8.3\ and\ 8.5)\ of\ \[MG\]'s\ code,\ which\ seems\ to\ do\ all\ his\ was\ intended\ to\ do\ also.\ \ Modified\ to\ also\ eliminate\ leading\ ./s.\ Modified\ to\ support\ filenames\ with\ spaces\ in\ them.\nNote:\ you\ may\ need\ to\ replace\ `\[file\ join\]\ \$dir\ \$x`\ with\ simply\ `\$x`.\ I\ had\ to.\nNote:\ you\ may\ need\ to\ replace\ \[file\ join\ \$dir\ \$x\]\ with\ simply\ \$x.\ I\ had\ to.\n======\n\ proc\ globRec\ \{\{dir\ .\}\ \{filespec\ \"*\"\}\ \{types\ \{b\ c\ f\ l\ p\ s\}\}\}\ \{\n\ \ set\ files\ \[glob\ -nocomplain\ -types\ \$types\ -dir\ \$dir\ --\ \$filespec\]\n\ \ foreach\ x\ \[glob\ -nocomplain\ -types\ \{d\}\ -dir\ \$dir\ --\ *\]\ \{\n\ \ \ set\ files\ \[concat\ \$files\ \[globRec\ \[file\ join\ \$dir\ \$x\]\ \$filespec\ \$types\]\]\n\ \ \}\n\ \ set\ filelist\ \{\}\n\ \ foreach\ x\ \$files\ \{\n\ \ \ while\ \{\[string\ range\ \$x\ 0\ 1\]==\"./\"\}\ \{\n\ \ \ \ regsub\ ./\ \$x\ \"\"\ x\n\ \ \ \}\n\ \ \ lappend\ filelist\ \$x\n\ \ \}\n\ \ return\ \$filelist\;\n\ \}\;#\ globRec\n\n\[jys\]\ –\ I\ wanted\ a\ recursive\ glob\ that\ would\ take\ the\ same\ options\ as\ glob,\ so\ I\ wrote\ this\ wrapper.\ I\ don't\ know\ if\ it\ works\ 100%\ with\ all\ options\ though,\ and\ it\ currently\ gets\ tripped\ up\ by\ glob\ spitting\ the\ dummy\ when\ it\ can't\ look\ inside\ a\ directory\ (generally\ 'cause\ of\ permissions).\n\ proc\ rglob\ \{args\}\ \{\n\ \ \ \ \ \ \ \ \ #\ This\ code\ requires\ -join\ and\ -nocomplain.\ We\ also\ remove\ the\ -types\ option,\ and\ then\ manually\ apply\ a\ filter\ at\ the\ end.\n\ \ \ \ \ \ \ \ \ set\ args\ \[linsert\ \$args\ 0\ -nocomplain\ -join\]\n\ \ \ \ \ \ \ \ \ if\ \{\[set\ types_index\ \[lsearch\ -exact\ \$args\ -types\]\]\ !=\ -1\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ types\ \[lindex\ \$args\ \[expr\ \{\$types_index+1\}\]\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ args\ \[lreplace\ \$args\ \$types_index\ \[expr\ \{\$types_index+1\}\]\]\n\ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ #\ Get\ inital\ matches.\n\ \ \ \ \ \ \ \ \ set\ matches\ \[glob\ \{*\}\$args\]\n\ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ #\ Keep\ adding\ *\ wildcards\ to\ search\ through\ subdirectories\ until\ there\ are\ no\ more\ levels\ of\ directories\ to\ search.\n\ \ \ \ \ \ \ \ \ while\ \{\[llength\ \[glob\ -types\ d\ \{*\}\[lreplace\ \$args\ end\ end\ *\]\]\]\ >\ 0\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ args\ \[linsert\ \$args\ end-1\ *\]\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ lappend\ matches\ \{*\}\[glob\ \{*\}\$args\]\n\ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ #\ Filter\ matches\ with\ -types\ option.\n\ \ \ \ \ \ \ \ \ if\ \{\[info\ exists\ types\]\}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ matches\ \[glob\ -nocomplain\ -types\ \$types\ \{*\}\$matches\]\}\n\ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ return\ \$matches\n\ \}\n----\n\[ES\]:\ '''findfile:'''\ This\ procedure\ was\ inspired\ by\ glob-r\ above\ and\ is\ customized\ to\ quickly\ find\ the\ first\ instance\ of\ a\ file\ in\ a\ given\ path.\n\n\ proc\ findfile\ \{\ dir\ fname\ \}\ \{\n\ \ \ \ \ \ \ \ \[llength\ \[set\ x\ \[glob\ -nocomplain\ -dir\ \$dir\ \$fname\]\]\]\n\ \ \ \ \}\ \{\n\ \ \ \ \ \ \ \ return\ \[lindex\ \$x\ 0\]\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ foreach\ i\ \[glob\ -nocomplain\ -type\ d\ -dir\ \$dir\ *\]\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \$i\ !=\ \$dir\ &&\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \[llength\ \[set\ x\ \[findfile\ \$i\ \$fname\]\]\]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ return\ \$x\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\}\n\ \}\n(Verified\ works\ with\ 8.6.)\n----\n\[MSW\]:\ \[pathentry\]:\ Entry\ widget/binding\ set\ using\ glob\ to\ offer\ quick\ auto-completion\ of\ paths\n----\n\[GPS\]:\ In\ the\ Tcl'ers\ chat\ this\ elegant\ solution\ was\ created\ by\ \[DKF\]:\n\n\ proc\ *\ args\ \{glob\ -nocomplain\ *\[join\ \$args\ \{\}\]\}\n\n(\[CMCc\]:\ Now\ try\ the\ same\ kind\ of\ composition\ and\ extension\ under\ /bin/sh\ :)\n\n\[MJ\]\ -\ Shouldn't\ this\ be:\n\ \n\ proc\ *\ args\ \{glob\ -nocomplain\ *\\\{\[join\ \$args\ ,\]\\\}\}\n\nBecause\ \[DKF\]'s\ version\ doesn't\ do\ what\ I\ expect\ it\ to\ do\ with\ multiple\ args\ (maybe\ my\ expectation\ is\ wrong)\ \n\n----\n\[EB\]:\ The\ \[changes\ in\ Tcl/Tk\ 8.4.9\]\ shows\ that\ ''tilde\ paths\ are\ not\ returned\ specially\ by\ \[glob\]'',\ but\ shouldn't\nthat\ have\ been\ done\ to\ avoid\ a\ security\ problem\ with\ ~\ expansion\ ?\ e.g:\n\n\ foreach\ file\ \[glob\ \"*\"\]\ \{\n\ \ \ file\ delete\ -force\ \$file\n\ \}\n\nwhere\ \[glob\]\ returns\ a\ file\ beginning\ with\ a\ ~\ ?\n\n\[Vince\]\ writes:\ for\ historical\ reasons\ the\ code\ above\ is\ considered\ wrong/buggy.\ \ You\ should\ write\ ''file\ delete\ -force\ ./\$file''.\ \ This\ is\ perhaps\ something\ that\ should\ be\ changed\ in\ the\ future,\ but\ it\ might\ well\ break\ some\ old\ code.\ \ There\ is\ even\ a\ bug\ report\ or\ patch\ somewhere\ on\ sf\ about\ this,\ I\ think\ (probably\ closed\ now).\n\n----\nSee\ also\ here:\ \[Matthias\ Hoffmann\ -\ Tcl-Code-Snippets\]!\n----\n\nHere\ is\ a\ proc\ that\ will\ list\ the\ directory\ tree\ under\ any\ given\ root,\ giving\ the\ full\ path\ name\ of\ all\ descendants.\ It\ embeds\ glob\ in\ a\ recursive\ call\;\ a\ directory\ with\ no\ descendants\ is\ the\ base\ case.\n======\n\ proc\ listTree\ \{rootdir_\}\ \{\n\ #\ Precondition:\ rootdir_\ is\ valid\ path\ \n\ \ \ \ \ set\ currentnodes\ \[glob\ -nocomplain\ -directory\ \$rootdir_\ -types\ d\ *\]\n\ \ \ \ \ if\ \{\[llength\ \$currentnodes\]\ <=\ 0\}\ \{\n\ \ \ \ \ #\ Base\ case:\ the\ current\ dir\ is\ a\ leaf,\ write\ out\ the\ leaf\ \n\ \ \ \ \ \ \ \ \ puts\ \$rootdir_\n\ \ \ \ \ \ \ \ \ return\n\ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ #\ write\ out\ the\ current\ node\ \n\ \ \ \ \ \ \ \ return\n\ \ \ \ \ #\ Recurse\ over\ all\ dirs\ at\ this\ level\n\ \ \ \ \ \ \ \ \ foreach\ node\ \$currentnodes\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ listTree\ \$node\n\ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \}\n\ \}\nlistTree\ \[pwd\]\n\ listTree\ \[pwd\]\n(Verified\ works\ with\ 8.6\ (and\ is\ surprisingly\ quick).)\nThat\ this\ isn't\ a\ Tcl\ built-in\ (or\ if\ it\ is,\ why\ is\ it\ is\ such\ a\ well-kept\ secret)\ strikes\ me\ as\ odd.\ \nI\ remember\ reading\ something\ about\ a\ pre-defined\ limit\ on\ depth\ of\ recursion\ in\nI\ remember\ reading\ something\ about\ a\ pre-defined\ limit\ on\ depth\ of\ recursion\ in\ Tcl,\ \nso\ this\ code\ is\ not\ guaranteed\ for\ arbitrarily\ deep\ file\ structures.\nBob\n\n\n\n\[kostix\]\ (04-Sep-07)\ notes\ that\ there's\ one\ trick\ with\ '''glob'''\ on\ Windows:\n\ glob\ -dir\ c:\ *\nwill\ list\ contents\ of\ ''the\ current\ working\ directory\ on\ drive\ C:,''\ not\ the\ contents\ of\ the\ root\ folder\ on\ that\ drive.\n======\n\n\ glob\ -dir\ c:/\ *\n======\nThe\ described\ behaviour\ is\ consistent\ with\ what\ is\ seen\ in\ '''cmd.exe'''\ command\ shell.\nThe\ described\ behaviour\ is\ consistent\ with\ what\ is\ seen\ in\ '''cmd.exe'''\n\n\[Zipguy\]\ 2013-02-07\ -\ Thanks\ \[kostix\]\ for\ pointing\ this\ out.\ \ I\ do\ use\ windows\n----\n\[Sarnold\]:\ Sometimes\ \[glob\]-like\ patterns\ are\ expected\ to\ be\ passed\ to\ some\ commands.\ This\ may\ lead\ to\ bugs,\ for\ example,\nin\ \[http://groups.google.com/group/comp.lang.tcl/browse_thread/thread/a2021acab428e198/b79eadada5bc5f3b#b79eadada5bc5f3b\]:\n**\ Stale\ links\ **\n\ set\ bar\ \{x\[y\]\}\n\ set\ foo(\$bar)\ yes\n\ array\ unset\ foo\ \$bar\n\ parray\ foo\ =>\ foo(x\[y\])\ still\ exists\nIf\ the\ pattern\ is\ not\ wildcarded,\ it\ tries\ to\ follow\ the\ link\;\ otherwise\ it\nWhat's\ the\ cure,\ Doctor?\ '''Unglob\ it!'''\n\n\ proc\ unglob\ \{x\}\ \{\n\ \ \ \ \ string\ map\ \{*\ \\\\*\ ?\ \\\\?\ \[\ \\\\\[\ \]\ \\\\\]\}\ \$x\n\ \}\n----\nIn\ a\ recent\ email\ thread\ on\ the\ \[Modules\]\ mailing\ list,\ a\ developer\ reported\ a\ change\ he\ found\ when\ beginning\ to\ use\ Tcl\ 8.5:\n\[Vince\]\ writes:\ for\ historical\ reasons\ the\ code\ above\ is\ considered\n===\n\$\ tclsh8.4\n%\ glob\ /home/\n/home\n%\ glob\ /home\n/home\n^D\n\$\ tclsh8.5\n%\ glob\ /home/\n/home/\n%\ glob\ /home\n/home\n^D\n\n===\nTurns\ out\ that\ the\ modules\ package\ was\ dependant\ on\ having\ the\ path\ returned\ without\ the\ trailing\ '''/''',\ and\ when\ 8.5\ started\ returning\ some\ paths\ with\ the\ slash,\ certain\ behaviors\ changed.\n\nFrom\ a\ purely\ technical\ point\ of\ view,\ the\ two\ forms\ of\ the\ name\ are\ considered\ equivalent\ by\ the\ operating\ systems\ with\ which\ I\ am\ familar\ (Ultrix,\ Solaris,\ etc.).\ I\ don't\ know\ if\ there\ are\ differences\ for\ variants\ or\ not.\ \n\n<<discussion>>\n} CALL {my revision glob} CALL {::oo::Obj439140 process revision/glob} CALL {::oo::Obj439138 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 56)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4