请问用什么方法能判断一个文件是否存在,谢谢!

请问用什么方法能判断一个文件是否存在,谢谢!
---------------------------------------------------------------

在 shell 中:

if [ -f filename ]; then
echo exist file
fi

判断目录是否存在:

if [ -d dirname ]; then
echo dir exist
fi

---------------------------------------------------------------

如果在C程序中:
access("filename",F_OK);
存在返回0,不存在返回-1

Published At
Categories with 服务器类
comments powered by Disqus