0

I have a file Locations.txt which has contents:

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

Where Type is the type of file and Dir1-4 are directories where specific music and doc files are stored. Everyday files get added to these folders.

What I tried is:

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)

//Othe LOC

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)  

///

getFiles()

I need to pass the path fetched from the file in os.walk.

Hunterr
  • 553
  • 1
  • 8
  • 28
  • are you familiar with the os library (import os)? and directory lookups? https://docs.python.org/2/library/os.html have you tried any code for detected recently added files based on date or anything similar? – glls May 24 '16 at 05:05
  • 1
    Possible duplicate of [How do you get a directory listing sorted by creation date in python?](http://stackoverflow.com/questions/168409/how-do-you-get-a-directory-listing-sorted-by-creation-date-in-python) – glls May 24 '16 at 05:09
  • I am somewhat. First I tried to get the modification time of each file `def modification_date(filename): t = os.path.getctime(filename) return datetime.datetime.fromtimestamp(t)` – Hunterr May 24 '16 at 05:11
  • check the above link it contains very useful info in order to achieve what you want – glls May 24 '16 at 05:12
  • @glls: I have multiple files in multiple directory that is listed in one other file. – Hunterr May 24 '16 at 05:12
  • then you will have to apply logic to verify the different directories in your code. instead of writing what you want, try writing some code and writing what you tried... – glls May 24 '16 at 05:14
  • Ok, let me edit a part of my question for what I have tried. – Hunterr May 24 '16 at 05:19
  • if you have any error messages alongside, it will help us help you – glls May 24 '16 at 05:20
  • @glls: can you have a look now – Hunterr May 24 '16 at 05:38

0 Answers0