sorted files list in objc
This commit is contained in:
36
engine/objc_utils.cpp
Normal file
36
engine/objc_utils.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "pch.h"
|
||||
#include "objc_utils.h"
|
||||
|
||||
#ifdef __OBJC__
|
||||
|
||||
|
||||
@implementation PathWithModDate
|
||||
@end
|
||||
|
||||
@implementation ObjcUtils
|
||||
+ (NSArray*)getFilesAtPathSortedByModificationDate:(NSString*)folderPath
|
||||
{
|
||||
NSArray *allPaths = [NSFileManager.defaultManager contentsOfDirectoryAtPath:folderPath error:nil];
|
||||
|
||||
NSMutableArray *sortedPaths = [NSMutableArray new];
|
||||
for (NSString *path in allPaths) {
|
||||
NSString *fullPath = [folderPath stringByAppendingPathComponent:path];
|
||||
|
||||
NSDictionary *attr = [NSFileManager.defaultManager attributesOfItemAtPath:fullPath error:nil];
|
||||
NSDate *modDate = [attr objectForKey:NSFileModificationDate];
|
||||
|
||||
PathWithModDate *pathWithDate = [[PathWithModDate alloc] init];
|
||||
pathWithDate.path = fullPath;
|
||||
pathWithDate.modDate = modDate;
|
||||
[sortedPaths addObject:pathWithDate];
|
||||
}
|
||||
|
||||
[sortedPaths sortUsingComparator:^(PathWithModDate *path1, PathWithModDate *path2) {
|
||||
// Descending (most recently modified first)
|
||||
return [path2.modDate compare:path1.modDate];
|
||||
}];
|
||||
|
||||
return sortedPaths;
|
||||
}
|
||||
@end
|
||||
#endif
|
||||
Reference in New Issue
Block a user