Hello guys. I'm not sure if i understand properly how os.walk store its results.
Im trying to do the following:
I'm checking a root folder for subsequent folders. There are several hundreds of em, and they are nested in somewaht uniform way.
I'm trying to check each subfolder, and if it ends with a four digit number, store it in a list.
I used a highly procedural code, and got to it, but the code is using os.listdir, meaning that i need to execute the function for each folder i want.
Is there a better way?
def ListadorPastas(pasta):
resultado = []
regex = "^[0-9]{4}"
padrao = re.compile(regex)
for p in os.listdir(pasta):
regexObject = re.match(padrao,p[-4:])
if (regexObject!=None):
resultado.append(regexObject.string)
else:
pass
return resultado
Also, i have a regex problem: this regex is matching the last four sliced digits of a expression. Sometime i have folders with 5 digits in the end, which ALSO will match. I tried using "$[0-9]{4}" but it returns me nothing. Any ideas why?
Thanks in advanced.
George