Notifications
Clear all
[Closed] sorting files according dates in MXS
2 Replies
Feb 26, 2017 5:00 pm
Here’s a function through DotNet to get a “comparable value” of file dates:
fn fileTime file =
(
dotnetFile = dotnetClass "System.IO.File"
fileDate = dotnetFile.GetLastWriteTime file
timeZero = (dotnetobject "system.datetime" 1980 1 1 0 0 0)
timeLapse = fileDate.subtract timeZero
ElapsedSeconds = timeLapse.TotalSeconds
ElapsedSeconds as integer
)
Now you can sort your files with any sorting method. For example, through maxLINQ
files = getFiles @"c:\foo\*.max"
sortedFiles = (_From Files).Sort(#'file=>fileTime file')
sortedFilesDescending = (_From Files).Sort(#'d:file=>fileTime file')
(maxLINQ thread: http://forums.cgsociety.org/showthread.php?f=98&t=1438311 )
Feb 26, 2017 5:00 pm
I’ve edited the function to return an integer (if not, maxLINQ.Sort does nothing).
With qsorting:
(
fn fileTime file =
(
dotnetFile = dotnetClass "System.IO.File"
fileDate = dotnetFile.GetLastWriteTime file
timeZero = (dotnetobject "system.datetime" 1980 1 1 0 0 0)
timeLapse = fileDate.subtract timeZero
ElapsedSeconds = timeLapse.TotalSeconds
ElapsedSeconds as integer
)
fn dateComparer x y DES:OFF =
(
dir = if DES then -1 else 1
xdate = fileTime x
ydate = fileTime y
(xdate-ydate) *dir
)
files = getFiles @"c:\foo\*.max"
qsort files dateComparer DES:ON
files
)