获取含指定字符的文件夹
def getAssignFolds(dir, foldruleName, absolueEqual=False):
foldList = []
for files in os.listdir(dir):
fullPath = os.path.join(dir, files)
if os.path.isdir(fullPath):
if absolueEqual:
if files == foldruleName:
foldList.append(fullPath)
else:
if not files.find(foldruleName) == -1:
foldList.append(fullPath)
return foldList
# 获取指定路径内,含aaa文件夹
file_dir = "D:\\test"
getAssignFolds(file_dir, "aaa")
# 获取叫aaa的文件夹
getAssignFolds(file_dir, "aaa",True)
# 获取该目录下的所有文件夹
getAssignFolds(file_dir, "")
获取文件名(截取最后一个点之前的所有字符)
def getFileName(fileFullName):
index = fileFullName.rfind(".")
fileName = fileFullName[1:index]
print (fileName)
return fileName
getFileName("11.22.43.exwe")