Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to filter files by creation date

Reply
Thread Tools

how to filter files by creation date

 
 
awel
Guest
Posts: n/a
 
      11-06-2007
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

 
Reply With Quote
 
 
 
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      11-06-2007
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
 
Reply With Quote
 
 
 
 
Neil McCallum
Guest
Posts: n/a
 
      11-06-2007


> 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


 
Reply With Quote
 
awel
Guest
Posts: n/a
 
      11-06-2007
On 6 nov, 09:00, Marc 'BlackJack' Rintsch <bj_...@gmx.net> wrote:
> 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

 
Reply With Quote
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      11-06-2007
On Tue, 06 Nov 2007 01:45:02 -0800, awel wrote:

> On 6 nov, 09:00, Marc 'BlackJack' Rintsch <bj_...@gmx.net> wrote:
>> 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
 
Reply With Quote
 
awel
Guest
Posts: n/a
 
      11-06-2007
On 6 nov, 11:27, Marc 'BlackJack' Rintsch <bj_...@gmx.net> wrote:
> On Tue, 06 Nov 2007 01:45:02 -0800, awel wrote:
> > On 6 nov, 09:00, Marc 'BlackJack' Rintsch <bj_...@gmx.net> wrote:
> >> 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'

 
Reply With Quote
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      11-06-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Globbing files by their creation date tkpmep@hotmail.com Python 3 01-17-2007 04:31 PM
How to (batch) set EXIF date taken and IPTC creation date and creation time for photos with filenames YYMMDDHHMMSS#.jpg? guercheLE@gmail.com Digital Photography 1 10-04-2005 07:15 PM
copy EXIF date to IPTC creation date Israel Hsu Digital Photography 0 08-04-2005 08:04 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57