Walk a directory/Recursively: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: elided redundant REXX word in the REXX version titles for REXX.)
m (→‎{{header|REXX}}: reinstated original program; changed/added comments, added an example output.)
Line 1,601: Line 1,601:
{{works with|Regina}}
{{works with|Regina}}
The following program was tested in a DOS window under Windows/XP and should work for all Microsoft Windows.
The following program was tested in a DOS window under Windows/XP and should work for all Microsoft Windows.
<lang rexx>/*REXX program shows files in a single directory that match a criteria.*/
<lang rexx>/*REXX program shows all files in a directory tree that match a given search criteria.*/
parse arg xdir; if xdir='' then xdir='\' /*Any DIR? Use default.*/
parse arg xdir; if xdir='' then xdir='\' /*Any DIR specified? Then use default.*/
@.=0 /*default in case ADDRESS fails. */
@.=0 /*default result in case ADDRESS fails.*/
trace off /*suppress REXX err msg for fails*/
dirCmd= 'DIR /b /s' /*the DOS command to do heavy lifting. */
trace off /*suppress REXX error message for fails*/
address system 'DIR' xdir '/b' with output stem @. /*issue the DIR cmd.*/
address system dirCmd xdir with output stem @. /*issue the DOS DIR command with option*/
if rc\==0 then do /*an error happened?*/
say '***error!*** from DIR' xDIR /*indicate que pasa.*/
if rc\==0 then do /*did the DOS DIR command get an error?*/
say 'return code=' rc /*show the Ret Code.*/
say '***error!*** from DIR' xDIR /*error message that shows "que pasa". */
exit rc /*exit with the RC.*/
say 'return code=' rc /*show the return code from DOS DIR.*/
end /* [↑] bad address.*/
exit rc /*exit with " " " " " */
#=@.rc /*number of entries.*/
end /* [↑] bad ADDRESS cmd (from DOS DIR)*/
if #==0 then #=' no ' /*use a word, ¬zero.*/
#=@.rc /*the number of @. entries generated.*/
if #==0 then #=' no ' /*use a better word choice for 0 (zero)*/
say center('directory ' xdir " has " # ' matching entries.',79,'')
say center('directory ' xdir " has " # ' matching entries.', 79, "")


do j=1 for #; say @.j; end /*show files that met criteria. */
do j=1 for #; say @.j /*show all the files that met criteria.*/
end /*j*/

exit @.0+rc /*stick a fork in it, we're done.*/</lang>
exit @.0+rc /*stick a fork in it, we're all done. */</lang>
'''output''' &nbsp; when the following was used: &nbsp; <tt> I:\firefox*.exe </tt>
<pre>
─────────────directory I:\firefox*.exe has 6 matching entries.─────────────
I:\FIREFOX\firefox.exe
I:\FIREFOX\INSTALL\Firefox Setup 1.5.0.1.exe
I:\FIREFOX\INSTALL\Firefox Setup 2.0.0.4.exe
I:\FIREFOX\INSTALL\Firefox Setup 3.0.4.exe
I:\FIREFOX\INSTALL\Firefox Setup 3.6 Beta 5.exe
I:\FIREFOX\INSTALL\Firefox Setup 4.0 Beta 11.exe
</pre>


===version 2===
===version 2===