为什么我在python2.7中导入os.walk时出错?

问题描述 投票:0回答:1
我需要在Linux服务器上递归地搜索目录/子目录以查找特定名称的目录,并在这些特定目录中检索文件。我尝试了两种方法,一种方法是导入os并调用os.walk,另一种方法是从os导入walk。下面的代码:

def getDeployedLibraries(): serverConfig() path = 'somePath' deployments = cmo.getLibraries() print(divider) print("Library Deployments:" ) print(divider) if deployments: deployedLibs = [] stagedLibs = [] archiveLibs = [] for dep in deployments: full_name = dep.getName() path = dep.getAbsoluteSourcePath() deployedLibs.append(path+full_name) for (dirpath, dirnames, files) in os.walk(path): for name in dirnames: if name != "shared-lib": dirnames.remove(name) for file in files: stagedLibs.append(file) for sLib in stagedLibs: if sLib not in deployedLibs: archiveLibs.append(sLib) f = open("filesToArchive.txt","w") f.write("\n".join(archiveLibs)) f.close() else: deploymentsList.append("No deployments of this type installed.") domainConfig() return deploymentsList

<< 'ImportError:无法导入名字漫游'。
此脚本的确连接到WLST,所以我认为也许我遇到了冲突,但没有发现任何迹象表明此类冲突。 

我需要在Linux服务器上递归地搜索目录/子目录以查找特定名称的目录,并在这些特定目录中检索文件。我尝试了2种方法,一种...

python linux python-2.x wlst
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.