Alguns dias atrás tive que mudar as permissões de um diretório contendo muitos sub-diretórios e arquivos (com toda certeza eu não iria fazer isso na mão :-D), resolvi então escrever um pequeno script para fazer esse trabalho. Falta ainda colocar o módulo optparse ou semelhante pra trabalhar os dados recebidos como parâmetro da linha de comando.
#!/usr/bin/env python
"""
Change directory and file permission recursively.
"""
import os
def changepermission(directory, dirperm, fileperm):
"""
This function change dir and file permission recursively.
e.g.: changepermission(/home/user, 0775, 0664)
"""
abspath = os.path.abspath(directory)
for item in os.listdir(abspath):
if os.path.isfile(abspath + '/' + item):
os.chmod(os.path.join(abspath, item), fileperm)
elif os.path.isdir(abspath + '/' + item):
os.chmod(os.path.join(abspath, item), fileperm)
changepermission(abspath + '/' + item, dirperm, fileperm)
if __name__ == '__main__':
changepermission('/path/to/directory', '775', '664')
2 comments:
hey! muda pra
os.chmod
"As captain you are an ambassador for the club and I'm ready for that," Van Persie told the official matchday programme."When I was 18 I didn't have a clue! Every day I was always surprised by something, when I went to training or when I had a game,bola tangkas online every day was just one big surprise for me. How people reacted after the game - the fans, players, media - it was all a surprise to me,ผลบอล I was just thinking about playing football.
Post a Comment