Skip to main content

sorting - Import multiple files from folder in order of date added



I have a folder that contains certain files I want to import. In my case those are .png files. As all the files I want to import contain the phrase "accum" in their filenames, I can use


SetDirectory[directory]; (*directory is string of the directory that contains the files*)
importString = "./*" <> "accum" <> "*";
files = Import[importString];

to obtain a list consisting of all the images I wanted to import. Of course this list is sorted by filename. What can I do to tell Import that the files should not be sorted by "name" but by other options like "date added" (which is what I want)?



Answer



Likely something like the following:


Import[#, "PNG"] & /@ SortBy[FileNames[importString], FileDate[#,"Creation"]&]


although I suspect there might be a more terse approach.


Comments