in reply to Sort by -M
As afoken++ points out, a Schwartzian transform would be both more efficient CPU wise as well as prevent the above unstable comparison function while sorting problem. For the Schwartzian transform, you would calculate the M time values only once before the sort commences.
No matter what you do, there is the possibility that in your sorted file name list, some file will not exist when it comes to process that list. I think the best you can do is be aware that some files in the sorted list may not exist after sorting. Adjust your sort comparison function so that no errors can occur during the actual sort and these non-existent files appear at one end or the other of the sort. Of course after you create the [filename, Mtime] array for the Schwartzian transform, you can grep out non-normal Mtime entries. However that will not prevent non-existent files from appearing in the final sorted result - you have to handle that no matter what.
Update: I was going to post some code, but I saw the code by tybalt89++. His code looks fine to me and "jives" with my advice. Be aware that even after the sort, some non-existent files may appear in the sorted list.
|
|---|