June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,30 +1,47 @@
|
|||
require unix/filestat.fs
|
||||
require unix/libc.fs
|
||||
|
||||
: $append ( from len to -- ) 2DUP >R >R COUNT + SWAP MOVE R> R@ C@ + R> C! ;
|
||||
|
||||
defer ls-filter
|
||||
|
||||
: 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 ;
|
||||
: dots? ( name len -- ? ) drop c@ [char] . = ;
|
||||
|
||||
: ls-r ( dir len -- )
|
||||
open-dir if drop exit then ( dirid)
|
||||
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 256 rot read-dir throw
|
||||
dup pad count + 256 rot read-dir throw
|
||||
while
|
||||
pad over dots? 0= if \ ignore current and parent dirs
|
||||
pad over recurse
|
||||
pad over ls-filter if
|
||||
cr pad swap type
|
||||
pad count + over dots? 0= if \ ignore all hidden names
|
||||
dup pad count rot + 2dup ls-filter if
|
||||
cr 2dup type
|
||||
then
|
||||
isdir if
|
||||
pad count + swap recurse
|
||||
else drop then
|
||||
else drop then
|
||||
repeat
|
||||
drop close-dir throw ;
|
||||
drop r> pad c!
|
||||
close-dir throw
|
||||
;
|
||||
|
||||
: c-file? ( str len -- ? )
|
||||
: ls-r ( dir len -- ) 0 pad c! (ls-r) ;
|
||||
|
||||
: c-files ( str len -- ? )
|
||||
dup 3 < if 2drop false exit then
|
||||
+ 1- dup c@ 32 or
|
||||
dup [char] c <> swap [char] h <> and if drop false exit then
|
||||
1- dup c@ [char] . <> if drop false exit then
|
||||
drop true ;
|
||||
' c-file? is ls-filter
|
||||
' c-files is ls-filter
|
||||
|
||||
s" ." ls-r
|
||||
: all-files ( str len -- ? ) 2drop true ;
|
||||
' all-files is ls-filter
|
||||
|
||||
s" ." ls-r cr
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
rootpath = "/home/user/music"
|
||||
pattern = r".mp3$"
|
||||
|
||||
for (root, dirs, files) in walkdir(rootpath)
|
||||
for file in files
|
||||
if ismatch(pattern, file) println(file) end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
// version 1.2.0
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun walkDirectoryRecursively(dirPath: String, pattern: Regex): Sequence<String> {
|
||||
val d = File(dirPath)
|
||||
require (d.exists() && d.isDirectory())
|
||||
return d.walk().map { it.name }.filter { it.matches(pattern) }.sorted().distinct() }
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val r = Regex("""^v(a|f).*\.h$""") // get all C header files beginning with 'va' or 'vf'
|
||||
val files = walkDirectoryRecursively("/usr/include", r)
|
||||
for (file in files) println(file)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue