diff --git a/vlib/os/os.v b/vlib/os/os.v index 8d0a8666c5..f08ea9e0ad 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -6,7 +6,7 @@ module os #include #include -//#include +#include #include //#include // for backtrace_symbols_fd @@ -347,28 +347,21 @@ pub fn mkdir(path string) { // rm removes file in `path`. pub fn rm(path string) { - $if windows { - // os.system2('del /f $path') - } - $else { C.remove(path.cstr()) - } // C.unlink(path.cstr()) } -/* -// TODO -fn rmdir(path, guard string) { - if !path.contains(guard) { - println('rmdir canceled because the path doesnt contain $guard') - return - } + +// rmdir removes a specified directory. +pub fn rmdir(path string) { $if !windows { + C.rmdir(path.cstr()) } $else { + C.RemoveDirectoryA(path.cstr()) } } -*/ + fn print_c_errno() { //C.printf('errno=%d err="%s"\n', errno, C.strerror(errno)) diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index 6fb5f30956..feafd1d0ce 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -34,9 +34,23 @@ fn test_write_and_read_string_to_file() { os.rm(filename) } +fn test_create_and_delete_folder() { + folder := './test1' + os.mkdir(folder) + + folder_contents := os.ls(folder) + assert folder_contents.len == 0 + + os.rmdir(folder) + + folder_exists := os.dir_exists(folder) + + assert folder_exists == false +} + fn test_dir() { $if windows { - assert os.dir('C:\a\b\c') == 'C:\a\b' + assert os.dir('C:\\a\\b\\c') == 'C:\\a\\b' } $else { assert os.dir('/var/tmp/foo') == '/var/tmp'