天天看點

python 擷取指定目錄的屬主

方式一:

def getowner(path2):

import os

import pwd

return pwd.getpwuid(os.stat(path2).st_uid).pw_name

方式二:

         import os

         if not os.path.exists(path2):

                   print "\"path2\" does not exsit."

                   exitcode(2)

         tmp=none

         if os.path.isdir(path2):

                   tmp=os.popen("ls -ld %s|awk '{print $3}' " % path2).readlines()

         else:

                   tmp=os.popen("ls -l %s|awk '{print $3}' "% path2).readlines()

         return tmp[0].strip()