I'm reading the files name from a directory. I am then chopping the output so I only have the first 10 characters from the filename, because of this is causes the output to have duplicates and file names I don't want included. This is my code:
import os
for path, subdirs, files in os.walk(r'C:\\Users\User\Documents'):
for filename in files:
f = os.path.join(path, filename)
print (str(f)[25:35])
This returns a list like this:
NUMBER0001
NUMBER0002
NUMBER0003
XXXXXXXX11
XXXXXXXX11
XXXXXXXX11
Expected Output:
NUMBER0001
NUMBER0002
NUMBER0003
How do I remove the files that don't start with 'NUMBER' from the list or how do I remove files that have XXX
at the start?
Also, is it possible to sort the output so it is in order of creation date?(The numbers at the end of the file name do not reference the order that the files were created).