-1

In Windows, if I ran:

dir NP_???.LAS

I get 2 files:

NP_123.LAS

NP_1234.LAS

Using fmatch with NP_????.LAS mask I get only NP_1234.LAS, not NP_123.LAS.

Below, the code I´m running:

def FindFiles(directory, pattern):
    flist=[]
    for root, dirs, files in os.walk(directory):
        for filename in fnmatch.filter(files, pattern):
            flist.append(os.path.join(root, filename))
    return flist

It´s possible to change this to get the same file list as dir command, using only one pattern?

Mauro Assis
  • 375
  • 1
  • 5
  • 22

1 Answers1

0

You could use re to give you more flexibility by allowing actual regular expressions. The regular expression "[0-9]{3,4}" matches either 3 or 4 digit numbers.

def FindFiles(directory, pattern):
    flist=[]
    for root, dirs, files in os.walk(directory):
        prog = re.compile("NP_[0-9]{3,4}.txt")
        for filename in filter(prog.match, files):
            flist.append(os.path.join(root, filename))
    return flist
F Horm
  • 13
  • 3