How do I check whether a file exists without exceptions?

后端 未结 30 1927
北海茫月
北海茫月 2020-11-21 05:07

How do I check if a file exists or not, without using the try statement?

30条回答
  •  醉酒成梦
    2020-11-21 05:34

    Here's a 1 line Python command for the Linux command line environment. I find this VERY HANDY since I'm not such a hot Bash guy.

    python -c "import os.path; print os.path.isfile('/path_to/file.xxx')"
    

    I hope this is helpful.

提交回复
热议问题