Question

I need to find files by wildcards in FTP directory, and there are files in the directory with the same name parts (mask is specified for this part of the name) and need to find the file at a later date of modification. Example: In the catalog there are files: AAA1, AAA2, AAA3, BBB1, BBB2. Looking for mask * AAA and BBB * files and AAAx BBBx a later date modification.

That's what has turned out:

dir_source = ftp.nlst()
masks = ["*.txt", "*.log"]

def listFiles(files, masks):
    findFiles = []
    parrent = re.compile("|".join(map(fnmatch.translate, masks)), re.I).match
    for filename in filter(parrent, files):
        d = {filename: int((ftp.sendcmd('MDTM ' + filename))[4:])}
        print d
    findFiles.append(max(d, key=lambda i: d[i]))
    return findFiles

print listFiles(dir_source, masks)

But it does not work... How to change the function?

Était-ce utile?

La solution

It's work!

def listFiles(files, masks):
    findFiles = []
    for x in masks:
        parrent = re.compile(fnmatch.translate(x)).match
        d = {filename: ((ftp.sendcmd('MDTM ' + filename))[4:]) for filename in filter(parrent, files)}
        print d
        findFiles.append(max(d, key=lambda i: d[i]))
    return findFiles

Maybe someone will come up with better?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top