os: is_file() (#6301)
parent
efa49bfbb7
commit
81778e507f
|
@ -1028,6 +1028,11 @@ pub fn is_dir(path string) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// is_file returns a `bool` indicating whether the given `path` is a file.
|
||||||
|
pub fn is_file(path string) bool {
|
||||||
|
return exists(path) && !is_dir(path)
|
||||||
|
}
|
||||||
|
|
||||||
// is_link returns a boolean indicating whether `path` is a link.
|
// is_link returns a boolean indicating whether `path` is a link.
|
||||||
pub fn is_link(path string) bool {
|
pub fn is_link(path string) bool {
|
||||||
$if windows {
|
$if windows {
|
||||||
|
|
|
@ -54,7 +54,37 @@ fn test_create_file() {
|
||||||
assert hello.len == os.file_size(filename)
|
assert hello.len == os.file_size(filename)
|
||||||
os.rm(filename)
|
os.rm(filename)
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
fn test_is_file() {
|
||||||
|
// Setup
|
||||||
|
work_dir := os.join_path(os.getwd(),'is_file_test')
|
||||||
|
os.mkdir_all(work_dir)
|
||||||
|
tfile := os.join_path(work_dir,'tmp_file')
|
||||||
|
// Test things that shouldn't be a file
|
||||||
|
assert os.is_file(work_dir) == false
|
||||||
|
assert os.is_file('non-existent_file.tmp') == false
|
||||||
|
// Test file
|
||||||
|
tfile_content := 'temporary file'
|
||||||
|
os.write_file(tfile, tfile_content)
|
||||||
|
assert os.is_file(tfile)
|
||||||
|
// Test dir symlinks
|
||||||
|
$if windows {
|
||||||
|
assert true
|
||||||
|
} $else {
|
||||||
|
dsymlink := os.join_path(work_dir,'dir_symlink')
|
||||||
|
os.system('ln -s $work_dir $dsymlink')
|
||||||
|
assert os.is_file(dsymlink) == false
|
||||||
|
}
|
||||||
|
// Test file symlinks
|
||||||
|
$if windows {
|
||||||
|
assert true
|
||||||
|
} $else {
|
||||||
|
fsymlink := os.join_path(work_dir,'file_symlink')
|
||||||
|
os.system('ln -s $tfile $fsymlink')
|
||||||
|
assert os.is_file(fsymlink)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
fn test_write_and_read_string_to_file() {
|
fn test_write_and_read_string_to_file() {
|
||||||
filename := './test1.txt'
|
filename := './test1.txt'
|
||||||
hello := 'hello world!'
|
hello := 'hello world!'
|
||||||
|
|
Loading…
Reference in New Issue