First find the path that needs to traverse the folder
Start traversal
Nsdirectoryenumerator *direnumerater = [FM enumeratoratpath:dir];
NSString *filepath = nil;
while (nil! = (FilePath = [Direnumerater nextobject])) {
NSString *msgdir = [NSString stringwithformat:@ "%@/localfile/%@", Kdocumentspath,filepath];
BOOL Isdir;
if ([FM fileexistsatpath:msgdir Isdirectory:&isdir]) {
if (!isdir) {
Delete irrelevant files
if ([[FilePath lastpathcomponent] isequaltostring:@ ". Ds_store "]) {
Continue
}
if ([[[FilePath Lastpathcomponent] isequaltostring:@ "index.htm"]) {
Continue
}
if ([[[FilePath Lastpathcomponent] isequaltostring:@ "index.html"]) {
Continue
}
Filename
NSString *filenamestr = [FilePath lastpathcomponent];
File path
NSString *filepath = Msgdir;
File modification Time
Nsdictionary *attributes = [FM attributesofitematpath:msgdir Error:nil];
NSDate *themodifidate;
if ((themodifidate = [Attributes Objectforkey:nsfilemodificationdate])) {
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[Formatter setdateformat:@] yyyy. Mm.dd hh:mm "];
NSString *datestr = [Formatter stringfromdate:themodifidate];
nsfilemanager* manager = [Nsfilemanager Defaultmanager];
File size
Long Long fileSize;
if ([manager Fileexistsatpath:filepath]) {
FileSize = [[Manager Attributesofitematpath:filepath Error:nil] fileSize];
}
Nsdictionary *dic = [nsdictionary dictionarywithobjectsandkeys:filenamestr,@ "name", filepath,@ "path", dateStr,@ "time @ (fileSize), @ "size", nil];
[Localfilearr Addobject:dic];
NSLog (@ "\ n-----File name%@\n_______ file path%@\n====== modification time%@\n-=-=-=-size%lld", filenamestr,filepath,datestr,filesize);
}
}
}
}
Properties of all files under a folder in iOS traversal program