且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查目录是否存在? "is_dir","file_exists"或两者?

更新时间:2023-11-29 15:56:22

在Unix系统上,两者都将返回true-在Unix中,所有内容都是文件,包括目录.但是要测试该名称是否被采用,您应该同时检查两者.可能会有一个名为"foo"的常规文件,这将阻止您创建目录名称"foo".

Both would return true on Unix systems - in Unix everything is a file, including directories. But to test if that name is taken, you should check both. There might be a regular file named 'foo', which would prevent you from creating a directory name 'foo'.