how to filter files by creation date

A

awel

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
 
M

Marc 'BlackJack' Rintsch

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
 
N

Neil McCallum

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
 
A

awel

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
 
M

Marc 'BlackJack' Rintsch

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
 
A

awel

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'
 
M

Marc 'BlackJack' Rintsch

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top