@@ -106,17 +106,25 @@ + (BOOL) mkdir:(NSString *) path {
106106 return err == nil ;
107107}
108108
109- + (NSData *) stat : (NSString *) path error : (NSError **) error {
110- NSMutableData *stat = [[NSMutableData alloc ]init];
109+ + (NSDictionary *) stat : (NSString *) path error : (NSError **) error {
110+ NSMutableDictionary *stat = [[NSMutableDictionary alloc ] init ];
111+ BOOL isDir = NO ;
111112 NSFileManager * fm = [NSFileManager defaultManager ];
112- NSData * info = [fm attributesOfItemAtPath: path error: &error];
113- [stat setValue: [info valueForKey: NSFileSystemSize ] forKey: @" size" ];
114- [stat setValue: path forKey: @" path" ];
115- [stat setValue: [path stringByDeletingPathExtension ] forKey: @" filename" ];
113+ if ([fm fileExistsAtPath: path isDirectory: &isDir] == NO ) {
114+ return nil ;
115+ }
116+ NSDictionary * info = [fm attributesOfItemAtPath: path error: &error];
117+ NSString * size = [NSString stringWithFormat: @" %d " , [info fileSize ]];
118+ NSString * filename = [path lastPathComponent ];
116119 NSDate * lastModified;
117120 [[NSURL fileURLWithPath: path] getResourceValue: &lastModified forKey: NSURLContentModificationDateKey error: &error];
118- [stat setValue: lastModified forKey: @" lastModified" ];
119- return stat;
121+ return @{
122+ @" size" : size,
123+ @" filename" : filename,
124+ @" path" : path,
125+ @" lastModified" : [NSString stringWithFormat: @" %d " , [lastModified timeIntervalSince1970 ]],
126+ @" type" : isDir ? @" directory" : @" file"
127+ };
120128}
121129
122130+ (BOOL ) exists : (NSString *) path {
@@ -867,7 +875,7 @@ - (id) init {
867875 NSError * error = nil ;
868876 NSArray * files = [[NSFileManager defaultManager ] contentsOfDirectoryAtPath: path error: &error];
869877
870- NSMutableArray * res = [NSMutableArray alloc ];
878+ NSMutableArray * res = [[ NSMutableArray alloc ] init ];
871879 if (isDir == YES ) {
872880 for (NSString * p in files) {
873881 NSString * filePath = [NSString stringWithFormat: @" %@ /%@ " , path, p];
0 commit comments