File path-related methods in nspathutilities, mainly the operation path
A path was obtained
NSString *documents = [Nssearchpathfordirectoriesindomains (nsdocumentdirectory, Nsuserdomainmask, YES) objectAtIndex : 0]; Get the document path <pre name= "code" class= "OBJC" >//---~~~/application/43a22272-f08c-4078-93a9-caf451bf9814/ Documents //~~~ is omitted
Nsarray *components = [documents pathcomponents]; The elements of each node of the path <pre name= "code" class= "OBJC" > "/", Users, admin, Library, Developer, Coresimulator, Devices, "87ab942e-1a11-479c-8010-1f5c36646658", data, Containers, data, application, "43a22272-f08c-4078-93a9-caf451bf9814", Documents
NSString *lastpathcomponent = [documents lastpathcomponent]; The last path node element //---Documents
NSString *stringbydeletinglastpathcomponent = [documents stringbydeletinglastpathcomponent];//Delete last path node element // ---~~~/application/3b14dae5-8890-42e1-8dc1-664bb35b6333
NSString *stringbyappendingpathcomponent = [Documents stringbyappendingpathcomponent:@ "New.txt"]; Add a path element //---~~~/application/20fed3fc-859a-4c56-945a-ffeeb17a93a2/documents/new.txt
NSString *pathextension = [stringByAppendingPathComponent pathextension]; Suffix of file //---TXT
NSString *stringbydeletingpathextension = [stringByAppendingPathComponent stringbydeletingpathextension]; Remove suffix name //---~~~/application/20fed3fc-859a-4c56-945a-ffeeb17a93a2/documents/new
NSString *stringbyappendingpathextension = [stringbydeletingpathextension stringbyappendingpathextension:@ "TXT"]; Add suffix name //---~~~/application/20fed3fc-859a-4c56-945a-ffeeb17a93a2/documents/new.txt
NSString *stringbyabbreviatingwithtildeinpath = [documents Stringbyabbreviatingwithtildeinpath]; To the relative path, the front is omitted with the wave number //---~/documents
NSString *stringbyexpandingtildeinpath = [Stringbyabbreviatingwithtildeinpath Stringbyexpandingtildeinpath]; Change the relative path to an absolute path
Nsarray *stringsbyappendingpaths = [Documents stringsbyappendingpaths:@[@ "a", @ "B", @ "C.txt"]; Batch join multiple paths, get an array of paths //---~~~/application/16474b22-b287-4f7c-9931-e7454b83822e/documents/a //---~~~/ application/16474b22-b287-4f7c-9931-e7454b83822e/documents/b //---~~~/application/ 16474b22-b287-4f7c-9931-e7454b83822e/documents/c.txt
iOS file path-related methods