473,394 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 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 10001
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matt Traxinger | last post by:
Is there a function that determines when a file was created? Like if I wanted to return all the files created in the last month from a directory, is there a way to do that? I've googled and googled...
5
by: [ EuGeNe ] | last post by:
Hi all, I would like to write a script that downloads one file from a ftp server if the file creation date satisfy a condition. I can't figure out how to find from a ftp server what is the...
3
by: Dave | last post by:
I recently did a search of my very first web site, through WebArchive, located here: http://web.archive.org/collections/web.html However, I'm seeking the creation date of my web site (and...
2
by: David Fickbohm | last post by:
People, I am trying to determine the creation date of files in a folder. I am using the following code to find the folder and confirm that files exist in the folder. If someone could give me an...
0
by: nek | last post by:
Greetings, I am running DB2 WSE V8.1, FP5 on W2K. The problem is not directly related to DB2 but as part of job, I need to manipulate files coming in from all sources. Under a main folder,...
3
by: Steven Blair | last post by:
Hi, I have a trace log file for a system I am writing. If the creation date is older than 14 days, I have to rename that file (File.Move). The next time a trace message is required a new file is...
2
by: Steve Teeples | last post by:
I am using the Filter property within OpenFileDialog. I understand how to filter files with extensions, but this time I need to filter files without extensions. Can someone tell me how this is...
6
by: fonzie | last post by:
Is there any way to include two unbound text boxes (for a start date and end date) to a filter-by-form? The users may want to filter by several different fields and they may want to include a date...
3
by: tkpmep | last post by:
I'd like to create a list of all files in a directory that were created after a certain date. How does one do this? I've used glob.glob to create a list of all files whose name matches a substring,...
3
by: MrDeej | last post by:
Hello! I am designing an import module in my access database for text files it looks like thisDim GammeltNavn As String Dim NyttNavn As String Dim MaskinNavn As String Dim fsoFileSearch As...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.