Walk a directory/Recursively: Difference between revisions
Content added Content deleted
(Added Kotlin) |
|||
Line 826: | Line 826: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|gforth|0. |
{{works with|gforth|0.7.9}} |
||
⚫ | |||
''Todo: track the full path and print it on matching files.'' |
|||
require unix/filestat.fs |
|||
⚫ | |||
require unix/libc.fs |
|||
: $append ( from len to -- ) 2DUP >R >R COUNT + SWAP MOVE R> R@ C@ + R> C! ; |
|||
⚫ | |||
⚫ | |||
else 2 = if dup c@ [char] . = swap 1+ c@ [char] . = and |
|||
else drop false then then ; |
|||
defer ls-filter |
|||
⚫ | |||
⚫ | |||
⚫ | |||
file-stat buffer: statbuf |
|||
: isdir ( addr u -- flag ) |
|||
statbuf lstat ?ior statbuf st_mode w@ S_IFMT and S_IFDIR = ; |
|||
⚫ | |||
pad c@ >r pad $append s" /" pad $append |
|||
⚫ | |||
begin |
begin |
||
dup pad 256 rot read-dir throw |
dup pad count + 256 rot read-dir throw |
||
while |
while |
||
pad over dots? 0= if \ ignore |
pad count + over dots? 0= if \ ignore all hidden names |
||
pad |
dup pad count rot + 2dup ls-filter if |
||
cr 2dup type |
|||
then |
|||
isdir if |
|||
pad count + swap recurse |
|||
else drop then |
else drop then |
||
else drop then |
else drop then |
||
repeat |
repeat |
||
drop |
drop r> pad c! |
||
close-dir throw |
|||
; |
|||
: |
: ls-r ( dir len -- ) 0 pad c! (ls-r) ; |
||
⚫ | |||
dup 3 < if 2drop false exit then |
dup 3 < if 2drop false exit then |
||
+ 1- dup c@ 32 or |
+ 1- dup c@ 32 or |
||
Line 855: | Line 869: | ||
1- dup c@ [char] . <> if drop false exit then |
1- dup c@ [char] . <> if drop false exit then |
||
drop true ; |
drop true ; |
||
' c- |
' c-files is ls-filter |
||
: all-files ( str len -- ? ) 2drop true ; |
|||
' all-files is ls-filter |
|||
s" ." ls-r |
s" ." ls-r cr |
||
</lang> |
|||
=={{header|Gambas}}== |
=={{header|Gambas}}== |