Ocstudy
Main.m
//
Starting from the home directory, find the path to all files with the file extension jpg
Created by Mark on 11-10-30.
Copyright 2011 __mycompanyname__. All rights reserved.
//
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
@autoreleasepool {
Nsfilemanager *manger;
Manger =[nsfilemanager defaultmanager];//Build a File Manager
NSString *home;
home= [@ "~" stringbyexpandingtildeinpath];//~ is a shorthand for the home directory, this method call is to specify the home directory to the home
Nsmutablearray *file;
FILE = [Nsmutablearray arraywithcapacity:42];//creates a new mutable array, 42 is random, does not affect the array extension, you can also write 41, as you like
For (NSString *filename in [Manger Enumeratoratpath:home]) {//Traverse each file path to find the file with the extension jpg, The Fast enumeration method makes it easier and quicker to access each element of an array than creating two enumerators (the following comment section)
if ([[FileName pathextension]
Isequalto: @ "jpg"]) {
[File Addobject:filename];
}
}
For (nsstring *filename in file) {
NSLog (@ "%@", filename);
}
Nsdirectoryenumerator *direnum;
Direnum = [Manger enumeratoratpath:home];
//
//
NSString *filename;
while (filename = [Direnum nextobject]) {
if ([[[FileName pathextension] Isequalto: @ "jpg"]) {
[File Addobject:filename];
// }
// }
//
Nsenumerator *fileenum;
Fileenum = [File Objectenumerator];
//
while (filename = [Fileenum nextobject]) {
NSLog (@ "%@", filename);
// }
}
return 0;
}
The output is as follows (partial):
2011-10-30 04:45:55.104 ocstudy[309:707] desktop/ not named _meitu_1.jpg
2011-10-30 04:45:55.105 ocstudy[309:707] desktop/ Software and Drivers /qq.app/contents/resources/guide1.jpg
2011-10-30 04:45:55.106 ocstudy[309:707] desktop/ Software and Drivers /qq.app/contents/resources/guide2.jpg
2011-10-30 04:45:55.106 ocstudy[309:707] desktop/ Software and Drivers /qq.app/contents/resources/guide3.jpg
2011-10-30 04:45:55.107 ocstudy[309:707] desktop/ Software and Drivers /qq.app/contents/resources/guide4.jpg
2011-10-30 04:45:55.107 ocstudy[309:707] desktop/ Software and Drivers /qq.app/contents/resources/guide5.jpg
2011-10-30 04:45:55.108 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F00/gktl.jpg
2011-10-30 04:45:55.108 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F00/ydff.jpg
2011-10-30 04:45:55.109 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F01/ajfw.jpg
2011-10-30 04:45:55.109 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F02/pxmw.jpg
2011-10-30 04:45:55.110 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F02/tbiy.jpg
2011-10-30 04:45:55.110 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F05/jijv.jpg
2011-10-30 04:45:55.111 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F05/muga.jpg
2011-10-30 04:45:55.111 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F05/nxon.jpg
2011-10-30 04:45:55.112 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F06/jrwj.jpg
2011-10-30 04:45:55.112 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F06/uqtd.jpg
2011-10-30 04:45:55.113 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F07/gwgq.jpg
2011-10-30 04:45:55.113 ocstudy[309:707] library/application support/iphone simulator/user/media/photos/thumbs/ F07/uspa.jpg