代码之家  ›  专栏  ›  技术社区  ›  Jon-Eric

如何使用python将共享网络文件设置为只读?

  •  0
  • Jon-Eric  · 技术社区  · 16 年前

    使用python,当文件位于网络共享(从Windows2003服务器提供服务)上时,将文件设置为只读的正确方法是什么?

    我在OSX(10.6.1)中运行python 2.6.2。

    当路径为本地时,以下代码将引发异常(如预期),但 os.chmod 当路径指向Windows共享时似乎没有效果。

    import os, stat
    
    path = '/Volumes/Temp/test.txt'
    
    # Create a test file.
    open(path, 'w').close()
    
    # Make the file read-only.
    os.chmod(path, stat.S_IREAD)
    
    # Try writing to it again. This should fail.
    open(path, 'w').close()
    
    1 回复  |  直到 16 年前
        1
  •  0
  •   jldupont    16 年前