xcode - IOS: copy a file in documents folder -


in project have 2 file .txt (in resources folder), how can copy them inside documents folder?

copies txtfile resource document if not present.

nsfilemanager *filemanager = [nsfilemanager defaultmanager]; nserror *error; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0];  nsstring *txtpath = [documentsdirectory stringbyappendingpathcomponent:@"txtfile.txt"];  if ([filemanager fileexistsatpath:txtpath] == no) {     nsstring *resourcepath = [[nsbundle mainbundle] pathforresource:@"txtfile" oftype:@"txt"];     [filemanager copyitematpath:resourcepath topath:txtpath error:&error]; } 

if want overwrite every time try this:

if ([filemanager fileexistsatpath:txtpath] == yes) {     [filemanager removeitematpath:txtpath error:&error]; }  nsstring *resourcepath = [[nsbundle mainbundle] pathforresource:@"txtfile" oftype:@"txt"]; [filemanager copyitematpath:resourcepath topath:txtpath error:&error]; 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -