473,787 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.t oday()
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 10090
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.f romtimestamp(os .stat('/home/bj/test.py').st_ct ime)
Out[439]: datetime.date(2 007, 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.5951 259
Nov 6 '07 #3
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.f romtimestamp(os .stat('/home/bj/test.py').st_ct ime)
Out[439]: datetime.date(2 007, 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.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.f romtimestamp(os .stat('/home/bj/test.py').st_ct ime)
Out[439]: datetime.date(2 007, 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.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.f romtimestamp(os .stat('/home/bj/test.py').st_ct ime)
Out[439]: datetime.date(2 007, 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.f romtimestamp(os .stat('/home/bj/test.py').st_ct ime)
Out[439]: datetime.date(2 007, 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
11331
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 but can't find what I'm looking for. Thanks
5
12464
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 creation date of the file (using python). Any idea?
3
24417
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 documents within it), but I don't know how. If I save the document to my desktop, it is listed as today's date in Properties. Is there a way to get the creation date/publish date of a web document
2
3514
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 idea how to check a creation date it would be appreciated. Thanks dave def delete_old_files (t:\dm\~\users)
0
4667
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, every subfolder signifies data coming from a different source. The source can further subdivide into more folders.
3
6010
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 created StreamWriter sw = new StreamWriter(path,true); The problem is, the creation date of this new file has the creation date of the previous log file :S and not the present date.
2
3792
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 done? -- Steve
6
8365
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 range search on the one date field. Instead of having the users type in
3
10199
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, but I don't see how I can use it to identify files by their creation date. Thanks in advance for the assistance. Thomas Philips
3
3233
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 FileSearch Set fsoFileSearch = Application.FileSearch With fsoFileSearch
0
9497
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.