Walk a directory/Recursively: Difference between revisions

no edit summary
(→‎{{header|C}}: For POSIX version: {{improve|C|Take improvements from Walk a directory/Non-recursively#C.}})
No edit summary
Line 1,243:
for(f <- root.andTree; if f.getName.endsWith(".mp3")) Console.println(f)
}</lang>
 
=={{header|Scheme}}==
Varies slightly depending on the implementation of scheme.
 
{{works with|Chicken Scheme}}
<lang scheme>
(use posix)
(use files)
(use srfi-13)
 
(define (walk FN PATH)
(for-each (lambda (ENTRY)
(cond ((not (null? ENTRY))
 
(let ((MYPATH (make-pathname PATH ENTRY)))
 
(cond ((directory-exists? MYPATH)
(walk FN MYPATH) ))
 
(FN MYPATH) )))) (directory PATH #t) ))
 
(walk (lambda (X) (cond ((string-suffix? ".scm" X) (display X)(newline) ))) "/home/user/")
</lang>
 
See also: '''(find-files ...)''' function in the '''posix''' module.
 
{{works with|Gauche}}
<lang scheme>
(use file.util)
(use srfi-13)
 
(define (walk FN PATH)
(for-each (lambda (ENTRY)
(cond ((not (null? ENTRY))
(let ((MYPATH ENTRY))
 
(cond ((file-is-directory? MYPATH)
(walk FN MYPATH) ))
(FN MYPATH) )))) (directory-list PATH :add-path? #t :children? #t ) ))
 
(walk (lambda (X) (cond ((string-suffix? ".scm" X) (display X)(newline) ))) "/home/user/")
</lang>
See also: '''(find-file-in-paths ...)''' function in the '''file.util''' module.
 
{{works with|PLT Scheme}}
<lang scheme>
#lang scheme
 
(require srfi/13)
 
(define (walk FN PATH)
(for-each (lambda (ENTRY)
(cond ((not (null? ENTRY))
 
(let ((MYPATH (build-path PATH ENTRY)))
 
(cond ((directory-exists? MYPATH)
(walk FN MYPATH) ))
(FN MYPATH) )))) (directory-list PATH)))
 
(walk (lambda (X) (cond ((string-suffix? ".scm" (path->string X)) (display X)(newline) ))) "/home/user/")
</lang>
See also: '''(find-files ...)''' function in the '''file''' module.
 
Sample output:
<lang scheme>
/home/user/one.scm
/home/user/lang/two.scm
[...]
</lang>
 
=={{header|Smalltalk}}==
Anonymous user