Posted By

silviud on 01/22/11


Tagged

python unix linux


Versions (?)

Python recursive change uid and gid (chown) of directory


 / Published in: Python
 

as you run chown -R user:group dir

  1. def _chown(path, uid, gid):
  2. os.chown(path, uid, gid)
  3. for item in os.listdir(path):
  4. itempath = os.path.join(path, item)
  5. if os.path.isfile(itempath):
  6. os.chown(itempath, uid, gid)
  7. elif os.path.isdir(itempath):
  8. os.chown(itempath, uid, gid)
  9. self._chown(itempath, uid, gid)

Report this snippet  

You need to login to post a comment.