471,316 Members | 1,304 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 software developers and data experts.

how to filter files by creation date

Hello All,

I am trying to to make a script to move all the files that has been
created at today's to another folder but my problem is the date format
that I receive from the 'os.stat [stat.ST_CTIME]' is different from
the one that I receive from the 'datetime.date.today()'.

Does someone could help me?
Here is my script:

import os, stat, time, datetime
a= "c:\\"
filesys = os.listdir(a)
today= datetime.date.today()
def get_create_time(a):
int_time = os.stat("c:\\")[stat.ST_CTIME]
str_time = time.ctime(int_time)
return str_time
#print filesys
for file in filesys:
create_time = get_create_time(a)
print file, create_time[-4:]
# print today

Thanks
Awel

Nov 6 '07 #1
6 9498
On Mon, 05 Nov 2007 23:33:16 -0800, awel wrote:
I am trying to to make a script to move all the files that has been
created at today's to another folder but my problem is the date format
that I receive from the 'os.stat [stat.ST_CTIME]' is different from
the one that I receive from the 'datetime.date.today()'.
Build a `datetime.date` object from the timestamp you get from the stat
call:

In [438]: !touch test.py

In [439]: datetime.date.fromtimestamp(os.stat('/home/bj/test.py').st_ctime)
Out[439]: datetime.date(2007, 11, 6)

Ciao,
Marc 'BlackJack' Rintsch
Nov 6 '07 #2

On Mon, 05 Nov 2007 23:33:16 -0800, awel wrote:
I am trying to to make a script to move all the files that has been
created at today's to another folder but my problem is the date format
that I receive from the 'os.stat [stat.ST_CTIME]' is different from
the one that I receive from the 'datetime.date.today()'.
In [28]: import time

In [29]: time.time()
Out[29]: 1194338141.5951259
Nov 6 '07 #3
On 6 nov, 09:00, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Mon, 05 Nov 2007 23:33:16 -0800, awel wrote:
I am trying to to make a script to move all the files that has been
created at today's to another folder but my problem is the date format
that I receive from the 'os.stat [stat.ST_CTIME]' is different from
the one that I receive from the 'datetime.date.today()'.

Build a `datetime.date` object from the timestamp you get from the stat
call:

In [438]: !touch test.py

In [439]: datetime.date.fromtimestamp(os.stat('/home/bj/test.py').st_ctime)
Out[439]: datetime.date(2007, 11, 6)

Ciao,
Marc 'BlackJack' Rintsch
Could you explain a little more because I am new in scripting?
Thanks
Awel

Nov 6 '07 #4
On Tue, 06 Nov 2007 01:45:02 -0800, awel wrote:
On 6 nov, 09:00, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
>On Mon, 05 Nov 2007 23:33:16 -0800, awel wrote:
I am trying to to make a script to move all the files that has been
created at today's to another folder but my problem is the date format
that I receive from the 'os.stat [stat.ST_CTIME]' is different from
the one that I receive from the 'datetime.date.today()'.

Build a `datetime.date` object from the timestamp you get from the stat
call:

In [438]: !touch test.py

In [439]: datetime.date.fromtimestamp(os.stat('/home/bj/test.py').st_ctime)
Out[439]: datetime.date(2007, 11, 6)

Ciao,
Marc 'BlackJack' Rintsch

Could you explain a little more because I am new in scripting?
Not really. I showed you the call I made and the result I got. How can I
be more clear and precise!?

Ciao,
Marc 'BlackJack' Rintsch
Nov 6 '07 #5
On 6 nov, 11:27, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Tue, 06 Nov 2007 01:45:02 -0800, awel wrote:
On 6 nov, 09:00, Marc 'BlackJack' Rintsch <bj_...@gmx.netwrote:
On Mon, 05 Nov 2007 23:33:16 -0800, awel wrote:
I am trying to to make a script to move all the files that has been
created at today's to another folder but my problem is the date format
that I receive from the 'os.stat [stat.ST_CTIME]' is different from
the one that I receive from the 'datetime.date.today()'.
Build a `datetime.date` object from the timestamp you get from the stat
call:
In [438]: !touch test.py
In [439]: datetime.date.fromtimestamp(os.stat('/home/bj/test.py').st_ctime)
Out[439]: datetime.date(2007, 11, 6)
Ciao,
Marc 'BlackJack' Rintsch
Could you explain a little more because I am new in scripting?

Not really. I showed you the call I made and the result I got. How can I
be more clear and precise!?

Ciao,
Marc 'BlackJack' Rintsch- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -
Ok but I run in Windows and I cannot understand your '!touch test.py'

Nov 6 '07 #6
On Tue, 06 Nov 2007 02:35:46 -0800, awel wrote:
>In [438]: !touch test.py
>In [439]: datetime.date.fromtimestamp(os.stat('/home/bj/test.py').st_ctime)
Out[439]: datetime.date(2007, 11, 6)
Could you explain a little more because I am new in scripting?

Not really. I showed you the call I made and the result I got. How can I
be more clear and precise!?

Ok but I run in Windows and I cannot understand your '!touch test.py'
Ah, sorry this was just to create and/or make sure that the file exists
and has today's date.

Ciao,
Marc 'BlackJack' Rintsch
Nov 6 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Matt Traxinger | last post: by
5 posts views Thread by [ EuGeNe ] | last post: by
2 posts views Thread by David Fickbohm | last post: by
3 posts views Thread by Steven Blair | last post: by
2 posts views Thread by Steve Teeples | last post: by
3 posts views Thread by tkpmep | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.