[Tutor] problem with os.chmod()
lonetwin
lonetwin <lonetwin@yahoo.com>
Wed, 12 Sep 2001 11:24:46 +0530 (IST)
Hi everybody,
I've got a problem with the os.chmod() function, it just doesn't
seem to do the right thing, let me explain, the code given below, is
something that I needed, I'm running this on a linux system, this code
changes the permissions of directories and files recursively. I initially
used os.chmod() function but it just screws up the permissions, so now I
do a os.system() to the chmod command, but I'd like to know what is
happening here....
###########################################################
#!/usr/bin/python
# chperm.py
# Usage: chperm.py <top-level dirname>
import os
def chmd(foo, dirname, names):
dirmode = 744
flmode = 700
names = [ os.path.join(dirname, x) for x in names ]
for fl in names:
if os.path.isdir(fl):
os.system('chmod %d "%s"' % (dirmode, fl))
# os.chmod(fl, dirmode) # <--- Does not work
elif os.path.isfile(fl):
os.system('chmod %d "%s"' % (flmode, fl))
# os.chmod(fl, flmode) # <--- Does not work
if __name__ == '__main__':
os.path.walk(os.sys.argv[1], chmd, None)
###########################################################
--
Peace
Steve
P.S: sincere sympathies to all Americans and all the victims of
terrorism on this dark day.