hi I am trying to sort my files in numeric order, not sure if this is possible. i have below list of files starting with numbers.
31_test1.txt
1_test1.txt
3_test4.txt
2_test2.txt
10_test3.txt
20_test4.txt
but when i use code below it give me out put as
10_test3.txt
1_test1.txt
20_test4.txt
2_test2.txt
31_test1.txt
3_test4.txt
my desire output is as below,
1_test1.txt
2_test2.txt
3_test4.txt
10_test3.txt
20_test4.txt
31_test1.txt
def getfilename(dirName, fileext):
#_logformat(" in get filename")
# create a list of file and sub directories
# names in the given directory
listOfFile = os.listdir(dirName)
#print(type(listOfFile))
listOfFile.sort()
allFiles = list()
# Iterate over all the entries
for entry in listOfFile:
# Create full path
fullPath = os.path.join(dirName, entry)
#print(fullPath)
# If entry is a directory then get the list of files in this directory
if os.path.isdir(fullPath):
allFiles = allFiles + getfilename(fullPath, fileext)
else:
if fileext in fullPath:
#print(fullPath)
allFiles.append(fullPath)
return allFiles