Nan*_* HE 52 directory perl file-io
要在使用文件之前查看文件是否存在,我们可以使用:
if (-e "filename.cgi")
{
#proceed with your code
}
Run Code Online (Sandbox Code Playgroud)
但是如何识别目录是否存在?
Bra*_*ace 94
使用-d(文件测试的完整列表)
if (-d "cgi-bin") {
# directory called cgi-bin exists
}
elsif (-e "cgi-bin") {
# cgi-bin exists but is not a directory
}
else {
# nothing called cgi-bin exists
}
Run Code Online (Sandbox Code Playgroud)
作为注释,-e不区分文件和目录.要检查是否存在某些内容并且是纯文件,请使用-f.
| 归档时间: |
|
| 查看次数: |
113614 次 |
| 最近记录: |