Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: count the number of files according to time modified  (Read 4051 times)

0 Members and 1 Guest are viewing this topic.

Carl_Johnson

  • Guest
count the number of files according to time modified
« on: March 30, 2010, 05:15:27 PM »
HELLO FRIENDS

i want to count number of files according to the date and then in between the time interval in the windows file system and save the out put in the text file
with details like this 

date                        time interval              count
=========================================

30/03/2010             0200-0400                 900
30/03/2010             0400-0600                 897
.................                  -------                           --
30/03/2010             2200-2400                 785

 ??? ??? ???


Waiting for Your replies

bye for now

ghostdog74



    Specialist

    Thanked: 27
    Re: count the number of files according to time modified
    « Reply #1 on: March 30, 2010, 07:29:27 PM »
    here's a Python script.

    Code: [Select]
    import os
    import time
    results={}
    path = os.path.join("c:\\","test")
    output=os.path.join("c:\\","test","output.txt")
    o=open(output,"w")
    o.write("date\t\ttime_intervale\t\tcount\n")
    for r,d,f in os.walk(path):
        for files in f:
            fpath=os.path.join(r,files)
            mtime = time.localtime(os.path.getmtime(fpath))
            file_date = time.strftime("%m/%d/%Y",mtime)
            file_time = int(time.strftime("%H%M",mtime))
            tag=""
            if file_time >= 200 and file_time <400:           
                tag="\t200-400"                       
            elif file_time >= 400 and file_time <600:
                tag="\t400-600"           
            elif file_time >= 800 and file_time <1000:
                tag="\t800-1000"
            elif file_time >= 1000 and file_time <1200:
                tag="\t1000-1200"
            elif file_time >= 1200 and file_time <1400:
                tag="\t1200-1400"
            elif file_time >= 1400 and file_time <1600:
                tag="\t1400-1600"           
            if tag:   
                results.setdefault(file_date+tag,0)       
                results[file_date+tag]+=1           

    for key in sorted(results.keys()):
        print key,results[key]
        o.write(key + "\t"+str(results[key]) + "\n")
    o.close()

    save as myscript.py and on command line,
    Code: [Select]
    c:\test> python myscript.py
    add the rest of the time as needed

    Salmon Trout

    • Guest
    Re: count the number of files according to time modified
    « Reply #2 on: March 31, 2010, 12:22:10 AM »
     ::)