문제

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?

도움이 되었습니까?

해결책

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?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top