且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-05-28 12:05:27

1
2
3
4
5
6
7
8
9
10
11
12
13
#-*- 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


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

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



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



本文转自 天道酬勤VIP 51CTO博客,原文链接:http://blog.51cto.com/tdcqvip/1944597