0
使用Python,當文件位於網絡共享位置(從Windows 2003服務器提供)時,將文件設置爲只讀的正確方法是什麼?如何使用Python以只讀方式創建共享網絡文件?
我在OS X(10.6.1)中運行Python 2.6.2。
當路徑是本地路徑時,以下代碼會引發異常(如預期的那樣),但當路徑指向Windows共享時,os.chmod
似乎不起作用。
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()
如果您從OS X命令窗口嘗試chmod,它工作嗎?否則,這可能是聯網互操作的限制。 – 2009-10-13 16:59:16