Python 判断文件是否存在和权限

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 判断文件是否存在和权限相关的知识,希望对你有一定的参考价值。

#-*- coding:utf-8 -*-
import os
import sys

if len(sys.argv) == 2:
	filename=sys.argv[1]
	if not os.path.isfile(filename):
		print ‘[-]‘ + filename + ‘does not exist.‘
		exit(0)
	if not os.access(filename, os.R_OK):
		print ‘[-]‘ + filename + ‘access denied.‘
		exit(0)
	print ‘[+] reading vulnerabilities from : ‘ + filename


执行结果:第一个是不存在的文件,第二个是存在且有权限的文件

技术分享



技术分享

本文出自 “天道酬勤” 博客,请务必保留此出处http://taindaochouqin.blog.51cto.com/12995943/1944596

以上是关于Python 判断文件是否存在和权限的主要内容,如果未能解决你的问题,请参考以下文章

python判断文件是否存在

python 判断目录和文件是否存在,若不存在即创建

python 判断文件和文件夹是否存在的方法 和一些文件常用操作符

Python 判断文件是否存在的三种方法

Python中如何判断文件是否存在?

Python判断文件是否存在的方法