Objective-c Foundation Framework example:looking for files find file
Nsfilemanager. The Nsfilemanager class lets you does stuff with the file system, like create directories, remove files, move files around, And get information about files.
Nsfilemanager: Lets you handle some file system things, such as creating directories, removing files, moving files, and getting information about files.
main.m//helloworld////Created by kfx on 15-5-4.//Copyright (c) 2015 COM. Mysupercompany. All rights reserved.//#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) {@autoreleasepo OL {Nsfilemanager *manager; Manager = [Nsfilemanager Defaultmanager]; NSString *home; home = [@ "~" Stringbyexpandingtildeinpath]; Nsdirectoryenumerator *direnum;//Directory Enumeration direnum = [Manager enumeratoratpath:home]; Nsmutablearray *files; Files = [Nsmutablearray arraywithcapacity:42]; NSString *filename; while (filename = [Direnum Nextobject]) {if ([[FileName pathextension] Isequalto: @ "jpg"]) { [Files Addobject:filename]; }} nsenumerator *fileenum; Fileenum = [Files Objectenumerator]; while (filename = [Fileenum nextobject]) {NSLog (@ "%@", filename); }} return 0;}
return 0;
}
Where in the file system to start looking at files?
Starting from the top level of your hard drive could take a long time, so let's just look in your home directory.
Start in the home directory.
Luckily, Unix (and OS X) have a shorthand character for the home directory, which is ~ (also known as the tilde).
UNIX and OS X have a simple string representing the home directory.
Objective-c Foundation Framework example:looking for files find file