LoginSignup
8
8

More than 5 years have passed since last update.

Pythonでos.mkdir時の注意

Posted at

(備忘録なメモです)

Pythonでディレクトリを作成するときに
os.mkdir(path,[mode])
http://docs.python.jp/2.7/library/os.html#os.mkdir

を使いますが

mkdir_NG_0777

os.mkdir("hoge",0777)

としてもパーミッション0777でディレクトリが作成されません。
マニュアルにあるとおりumaskがかかるので以下の記事で説明した挙動を受けます。
(つまり第2パラメータは、パーミッションの設定ではありません!)

参考:
Linuxのファイル・ディレクトリ作成した時のパーミッション (umask)
http://qiita.com/yuki2006@github/items/3774bf765eb5ef7deabc

つまり以下のようにしないといけません。

mkdir_OK_0777

os.mkdir("hoge")
os.chmod("hoge",0777)

ちょっといけてない(冗長な)感じがしますがどうなんでしょうか。。
(いい方法がありましたら教えて下さい。

8
8
9

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8