import os def getAllFile(*names): if len(names) == 0: return "" else: allList = [] for name in names: fileAndDirString = os.popen("ls -l "+name).read() fileAndDirStringDo = "\n".join(fileAndDirString.split("\n")[1:-1]) if fileAndDirStringDo: fileAndDirList = [fileOrDir.split(" ")[0]+" "+name+"/"+fileOrDir.split(" ")[-1] for fileOrDir in fileAndDirStringDo.split("\n")] allList.extend(fileAndDirList) # print(allList) fileList = [] dirList = [] for fileAndDir in allList: # print(fileAndDir) if fileAndDir[0] == "-": fileList.append(fileAndDir.split(" ")[-1]) else: dirList.append(fileAndDir.split(" ")[-1]) return "\n".join(fileList)+"\n"+getAllFile(*dirList) r = getAllFile("/home/taomin") print(r)
原文地址:https://www.cnblogs.com/taomin/p/10459528.html
时间: 2024-10-29 04:03:08