objective c - some operations on files -


I wrote this program, but could not get the output, every time I run this program, only me 1 NSLEG statement I have also created a file on this path and content.

  #import & lt; Foundation / Foundation. H & gt; Int main (int argc, const char * argv []) {@autoreleasepool {NSString * fName = @ "/ user / sahil / documents / newfile / commands"; NSFileManager * fm; NSDictionary * attr; FM = [NSFileManager default manager]; If ([FM filexstatspeap: FNAM] == no) {NSLog ("file does not exist"); Return 1; } If (([FM Copy Itamsteth: FNName Tupath: @ "Newfile 1" error: NULL] == Faucet) {NSLog ("" File Copy Failed "); Return 2; } If (content of AquaTall (FMM: FNM and path: @ "Newfile 1"] == no =) {NSLog (@ "file is not ="); Return 3; } If (path [from "FM Hill Itam Pat: @" Newfile 1 ": @" Newfile 2 "error: NULL] == faucet) {NSLog (@" Rename file is unsuccessful "); Return 4; } If the ("attr = [FM attributesoffitemet path: @" Newfile 2 "error: NULL]) == zero () {NSLOG (@" file attributes can not be received "); return 5;} NSLog (@" file size % Llu bytes ", [[Atri ObjectForcae: NSF file size] unsigned logging valley]; if ([FM deletion iTEMPT: FNAM error: NULL] == faucet) {NSLog (@" Failed to delete file "); return 6 ;} NSLog (@ "All Ops were successful"); NSLog (@ "% @", [NSString string with contentoffiff L: @ "Newfile 2" encoding: NSTF 8 string encoding error: NULL]);} Return 0;}  

Please help me with this problem. Thanks

  if ([fm fileExistsAtPath: fName] == no) {nslog (@ "File does not exist"); Return1;}  

If prints NSLog then no further execution will be performed in this program.

Remove return 1; statement.

It assumes that "I only have 1 N SOL statement. "It means: NSLog (@" File does not exist "); executes.

  if ([fm copyItemAtPath: fName ToPath: @ "newfile1" error: NULL] == faucet) {NSLOG (@ "File Copy Failed" ); Return 2; }  

Adding Error Logging:

  NSError * Error; If ([FM Copy ITEMTAP: FNM Toothpath: @ "Newfile 1" error: & amp; Error] == Faucet) {NSLOG ("" file copy failed, error:% @ ", error); Return 2; }  

Comments