【发布时间】:2016-09-10 13:33:47
【问题描述】:
如果想获得类似于 Bash 的 -d if 条件的功能。
我知道如何使用fileExistsAtPath() 测试文件是否存在,如果文件存在则返回布尔值“true”,如果不存在则返回“false”(假设path 是包含路径的字符串到文件):
if NSFileManager.fileExistsAtPath(path) {
print("File exists")
} else {
print("File does not exist")
}
但是,我想检查path中指定的路径是否是目录,类似于下面的bash代码:
if [ -d "$path" ]; then
echo "$path is a directory"
elif [ -f "$path" ]; then
# this is effectively the same as fileExistsAtPath()
echo "$path is a file"
fi
这是否可能,如果可以,应该如何执行?
【问题讨论】:
-
我同意,抱歉。我已将此标记为重复。
标签: swift directory swift2 nsfilemanager