python - 创建的目录具有错误的权限(被锁定)

标签 python python-2.7 directory

我正在使用我正在编写的程序创建一个日志目录:

def create_dir(dirpath):
    if not os.path.exists(dirpath):
        os.mkdir(dirpath)

当我运行程序时有时它会创建带有锁的目录(根据我的pycharm):

enter image description here enter image description here

我尝试将模式更改为 07770o777(默认),但它仍然会创建锁定文件并强制我使用 sudo 权限来读取或读取删除该文件。有没有一种方法可以在不锁定我的情况下创建目录?

最佳答案

这对我来说非常有效:

dir_path = "path/to/directory/including/directory/name"
if not os.path.exists(os.path.dirname(dir_path)):
    os.makedirs(os.path.dirname(dir_path))

关于python - 创建的目录具有错误的权限(被锁定),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45986427/

相关文章:

c# - 在 C# 中将目录 NAME 设为只读

linux - 目录路径作为 bash 中的命令行参数

python - 无法使用selenium从页面中名为 'heading'的每个类获取数据

python - 连接到数据库后执行原始 SQL

python - pandas查询方法中关键字 'columns'是什么意思?

python - numpy.fft() 返回值振幅+相移或角度是多少?

python - 在 python 27 中,如何将带参数的方法传递给类的 __init__()?

python - python2.7 中的正则表达式

python - 如何使用 wxPython 以正确的大小打开 GUI?

c# - 如何在 C# 中重命名文件夹/目录?