使用python从多个目录中获取最新文件

时间:2016-05-24 05:00:29

标签: python list file

我有一个文件Type Dir1 Dir2 Dir3 Dir4 Music D:\files1\music D:\files2\music D:\files3\music D:\files4\music Docs E:\files1\doc D:\files2\doc D:\files3\doc D:\files4\doc ,其中包含内容:

import fileinput
lDir=[]


def getFiles():
    fname= 'D:\server_logs\locations.txt'
    for line in fileinput.input([fname], openhook=fileinput.hook_compressed):
        if "Dir1 Dir2 Dir3 Dir4"  in line:
                continue
        else:   
            lDir.append(line)

    for l in lDir:
            print l
            """
            Now first I want to display Music files that were added yesterday in these directories
            Add all new files of Music type and pass the latest files to another function to process further

            func2(*list_of_new_files*)

            After this func2 is processed I want all Latest Docs Files to pass to func2()
            """

def modification_date(filename):
    t = os.path.getctime(filename)
    return datetime.datetime.fromtimestamp(t)

其中Type是文件类型,Dir1-4是存储特定音乐和doc文件的目录。 日常文件会添加到这些文件夹中。

我尝试的是:

for root, dirs, files in sorted(os.walk("D:\\files1\\music")):
    appnm="Music" 

    if appnm == root.split("\\")[-1] and len(files)>0:
        for file in files:
            if file.endswith(".mp3"):
                file_created_time = modification_date(root+'\\'+file)
                if file_created_time :
                    file_path= os.path.join(root, file) 
                    my_files.append(file_path)  

// Othe LOC

getFiles()

///

{{1}}

我需要传递从os.walk中的文件中获取的路径。

0 个答案:

没有答案
相关问题