怎样使用 Python 来判断一个路径是否存在判断一个路径是文件还是目录 判断一个路径是否存在


怎样使用 Python 来判断一个路径是否存在判断一个路径是文件还是目录

判断一个路径是否存在

可以判断一个文件或目录(文件夹)是否存在

    import os.path
    os.path.exists(path);
  • 1
  • 2
  • 1
  • 2

判断一个文件是否存在

    import os.path
    os.path.isfile(path);
  • 1
  • 2
  • 1
  • 2

判断一个目录(文件夹)是否存在

    import os.path
    os.path.isdir(path);
  • 1
  • 2
  • 1
  • 2

判断一个路径是文件还是目录(文件夹)

  • 方法一
    import os.path
    os.path.isdir(path);
    # 返回 True 表示是目录(文件夹)

  • 方法二
    import os.path
    os.path.isfile(path);
    # 返回 True 表示是文件
 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM