Probably a very easy question, but I could not find the answer, so it would be very nice if you can help me:

Let us say I have 10 files, all with the extension .dat. Using

data = Import[#, "Table"] & /@ FileNames["*.dat"]; 

I can import all .dat files in a folder.

However, I want Mathematica to order these .dat files by their alteration date just like I can do it under Windows with a right click > Sort by > alteration date. I want Mathematica to import the files in exactly this order. How might I do this?


1 Answer 1

dateOrdered = ((names = FileNames["*.dat"])[[Ordering[ FileDate[#, "Modification"] & /@ names]]]);

data = Import[#, "Table"] & /@ dateOrdered;

This will import with oldest modification date first, most recent last.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.