mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
os: walk() function
This commit is contained in:
committed by
Alexander Medvednikov
parent
580abe0de4
commit
98c016b41d
19
vlib/os/os.v
19
vlib/os/os.v
@@ -828,6 +828,25 @@ pub fn walk_ext(path, ext string) []string {
|
||||
return res
|
||||
}
|
||||
|
||||
// walk recursively traverse the given directory path.
|
||||
// When a file is encountred it will call the callback function with current file as argument.
|
||||
pub fn walk(path string, fnc fn(path string)) {
|
||||
if !os.is_dir(path) {
|
||||
return
|
||||
}
|
||||
mut files := os.ls(path) or { panic(err) }
|
||||
for file in files {
|
||||
p := path + os.path_separator + file
|
||||
if os.is_dir(p) {
|
||||
walk(p, fnc)
|
||||
}
|
||||
else if os.file_exists(p) {
|
||||
fnc(p)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
pub fn signal(signum int, handler voidptr) {
|
||||
C.signal(signum, handler)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user