473,422 Members | 1,759 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,422 software developers and data experts.

Globbing files by their creation date

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

Jan 16 '07 #1
3 10004

ThomasI've used glob.glob to create a list of all files whose name
Thomasmatches a substring, but I don't see how I can use it to
Thomasidentify files by their creation date.

Sumthin' like:

files = [f for f in glob.glob(globpat)
if os.path.getctime(f) timethreshold]

Define globpat and timethreshold accordingly. You sure you don't mean
modification time? If so, change getctime to getmtime.

Skip
Jan 16 '07 #2
On Tue, 16 Jan 2007 07:44:29 -0600, skip wrote:
ThomasI've used glob.glob to create a list of all files whose name
Thomasmatches a substring, but I don't see how I can use it to
Thomasidentify files by their creation date.

Sumthin' like:

files = [f for f in glob.glob(globpat)
if os.path.getctime(f) timethreshold]

Define globpat and timethreshold accordingly. You sure you don't mean
modification time? If so, change getctime to getmtime.
help(os.path.getctime)

getctime(filename)
Return the metadata change time of a file, reported by os.stat().

Note that _change_ time != creation time. Also for all files you probably
want os.listdir() instead of glob.

--
James Antill -- ja***@and.org
http://www.and.org/and-httpd/ -- $2,000 security guarantee
http://www.and.org/vstr/
Jan 16 '07 #3

Thanks a mill - os.path.getctime(f) is what I needed. Unfortunately, my
attempts to turn the integer it returns into a date have failed.
>>os.path.getctime(fn) #fn was created today, 1/17/2007
1168955503

I tried to convert this to a date object by typing
>>>datetime.date.fromordinal(1168955503)
Traceback (most recent call last):
File "<pyshell#9>", line 1, in -toplevel-
datetime.date.fromordinal(1168955503)
ValueError: year is out of range

How can I do the conversion? I'm trying to identify all files that were
created after YYYY/MM/DD.

For a quick sanity check, I ran
>>datetime.date.today().toordinal()
732693

which is orders of magnitude smaller than the number returned by
os.path.getctime(fn).

Thanks in advance for your help

Thomas Philips

Jan 17 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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: Raed Sawalha | last post by:
I wondering if it possilble to get the directory files ordered by creation date string files = System.IO.Directory.GetFiles(strPath,"*.msg") can I sort the returned file by creation date? ...
1
by: Amjad | last post by:
I want to sort files in a specified folder by their creation date and then display their names (sorted by the creation date) in a textbox for example. How would you do that? Dim dir As New...
1
by: Martin Ho | last post by:
Two questions: 1.) I am copying a whole bunch of files from one directory, but I need to do a if command to copy on those which date of creation is the same as today's date. How do I do this...
3
by: Daz | last post by:
Hi everyone! This is my first time posting in this group, although I have been watching it for the past few months and have to say this is possibly the best group I have seen on Google so far!...
2
by: Thomas Bauer | last post by:
Hello, Call DeleteFiles bgW_DeleteFilesProcess = new DeleteFiles(); bgW_DeleteFilesProcess.RunAsync( folder, 5, "*.txt", new RunWorkerCompletedEventHandler( RunWorkerCompleted_DeleteFiles_TXT )...
0
by: Kenneth Porter | last post by:
Due to a mis-feature in Windows filesystems, I need a globbing function in C or C++ that can emulate the globbing done by the built-in FindFirstFile API. The license should allow it to be...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
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...
0
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,...
0
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...
0
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...

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.