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

Sort files by date

Hi.

I'm looking for some way to sort files by date.

I'm usin glob module to list a directiry, but files are sorted by name.
import glob
path = "./"
for ScannedFile in glob.glob(path):

.... print ScannedFile

I googled my problem, but did not find any solution, neither in this
newsgroup.

Can anyone help me ?

Thanks
Jul 21 '05 #1
3 8770
fargo wrote:
I'm looking for some way to sort files by date.


you could do something like:

l = [(os.stat(i).st_mtime, i) for i in glob.glob('*')]
l.sort()
files = [i[1] for i in l]

Jeremy

--
Jeremy Sanders
http://www.jeremysanders.net/
Jul 21 '05 #2
Jeremy Sanders wrote:
you could do something like:

l = [(os.stat(i).st_mtime, i) for i in glob.glob('*')]
l.sort()
files = [i[1] for i in l]


Thank you for your help, this is excatly what I wasa looking for.
Jul 21 '05 #3
Jeremy Sanders wrote:
fargo wrote:

I'm looking for some way to sort files by date.

you could do something like:

l = [(os.stat(i).st_mtime, i) for i in glob.glob('*')]
l.sort()
files = [i[1] for i in l]

Jeremy

If you have 2.4 or later:

def mtime(filename):
return os.stat(filename).st_mtime

lst = sorted(glob.glob('*'), key=mtime)

--Scott David Daniels
Sc***********@Acm.Org
Jul 21 '05 #4

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

Similar topics

4
by: Jake | last post by:
Im using the following code to display the contents of a directory: <% Set objFso = CreateObject("Scripting.FileSystemObject") Set objFiles = objFso.GetFolder(Server.MapPath(".")) Set fileList...
5
by: SteM | last post by:
Hi!! I need something like a "sortfunction" because i want to sort the files in a directory x by name or date. i can't find any system function in c++ - any ideas, examples?? Thx, SteM
5
by: Jurgen Oerlemans | last post by:
Hello, I created an array of files in a directory by doing a: Dim FileArray As String() = IO.Directory.GetFiles(QueueSource, "*.Q") My question is: How can I sort this array on the...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
8
by: mesterak | last post by:
I'm trying to write a text log file processor but am having significant performance issues. * On average, there are about 100-200 files to process each file being about 1MB in size. * Typically...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
4
by: jonathan184 | last post by:
Hi I have a perl script, basically what it is suppose to do is check a folder with files. Now the files are checked using a timestamp with the command ls -l so the timestamp in this format is...
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
1
by: James Hahn | last post by:
I have a ListView that displays files selected from various folders using a user-specified selection rule. I want to sort the files in various ways and have implemented a sorter class to do it,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.