mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
Checks if dir given exists and is a directory before ls
This commit is contained in:
parent
ec87ca37fa
commit
ad5e1fd8d4
@ -516,7 +516,7 @@ mut args := ''
|
|||||||
|
|
||||||
fn (c &V) v_files_from_dir(dir string) []string {
|
fn (c &V) v_files_from_dir(dir string) []string {
|
||||||
mut res := []string
|
mut res := []string
|
||||||
if !os.file_exists(dir) {
|
if !os.dir_exists(dir) {
|
||||||
panic('$dir doesn\'t exist')
|
panic('$dir doesn\'t exist')
|
||||||
}
|
}
|
||||||
mut files := os.ls(dir)
|
mut files := os.ls(dir)
|
||||||
|
12
os/os.v
12
os/os.v
@ -331,6 +331,18 @@ pub fn file_exists(path string) bool {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn dir_exists(path string) bool {
|
||||||
|
res := false
|
||||||
|
if file_exists(path) {
|
||||||
|
# DIR *dir = opendir(path.str);
|
||||||
|
# res = dir != NULL;
|
||||||
|
if res {
|
||||||
|
# closedir(dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
// `mkdir` creates a new directory with the specified path.
|
// `mkdir` creates a new directory with the specified path.
|
||||||
pub fn mkdir(path string) {
|
pub fn mkdir(path string) {
|
||||||
$if windows {
|
$if windows {
|
||||||
|
Loading…
Reference in New Issue
Block a user