Jump to content

Walk a directory/Recursively: Difference between revisions

(Added Kotlin)
Line 826:
 
=={{header|Forth}}==
{{works with|gforth|0.67.29}}
<lang forth>defer ls-filter
''Todo: track the full path and print it on matching files.''
require unix/filestat.fs
<lang forth>defer ls-filter
require unix/libc.fs
 
: $append ( from len to -- ) 2DUP >R >R COUNT + SWAP MOVE R> R@ C@ + R> C! ;
: dots? ( name len -- ? )
dup 1 = if drop c@ [char] . =
else 2 = if dup c@ [char] . = swap 1+ c@ [char] . = and
else drop false then then ;
 
defer ls-filter
: ls-r ( dir len -- )
 
open-dir if drop exit then ( dirid)
: dots? dup( 1name len -- ? ) = if drop c@ [char] . = ;
 
file-stat buffer: statbuf
 
: isdir ( addr u -- flag )
statbuf lstat ?ior statbuf st_mode w@ S_IFMT and S_IFDIR = ;
 
: (ls-r) ( dir len -- )
pad c@ >r pad $append s" /" pad $append
pad count open-dir if drop r> pad c! exit then ( dirid)
begin
dup pad count + 256 rot read-dir throw
while
pad count + over dots? 0= if \ ignore current andall parenthidden dirsnames
dup pad overcount rot + 2dup ls-filter recurseif
pad over ls-filtercr if2dup type
cr pad swap typethen
isdir if
pad count + swap recurse
else drop then
else drop then
repeat
drop close-dir throwr> ;pad c!
close-dir throw
;
 
: cls-file?r ( strdir len -- ?) 0 pad c! (ls-r) ;
 
: dots?c-files ( namestr len -- ? )
dup 3 < if 2drop false exit then
+ 1- dup c@ 32 or
Line 855 ⟶ 869:
1- dup c@ [char] . <> if drop false exit then
drop true ;
' c-file?files is ls-filter
 
: all-files ( str len -- ? ) 2drop true ;
' all-files is ls-filter
 
s" ." ls-r</lang> cr
</lang>
 
=={{header|Gambas}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.