Noob need help on NSFileManager

Discussion in 'Mac Programming' started by freeme007, Mar 25, 2011.

  1. freeme007 macrumors regular

    Sep 21, 2008

    I'm trying to learn how NSFileManger works and I want to test out some methods with files that i have created. Let say the file name is called "testFile". Now the question is where do i put the file, in which folder? I tried the fileExistsAtPath method and it keeps giving me the file does not exist message. By the way, im using Xcode 4

    Thank you for your precious time.
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Post the code that doesn't work.

    1. Describe what you expected to happen.
    2. Describe what actually happened. (Include any error messages)
  3. gnasher729 macrumors P6


    Nov 25, 2005
    Hint: To do anything with a file, most operating system functions will want the complete path. That might be something like "/Users/freeme007/testFile" or "/Users/freeme007/Documents/testFile".

    I'd have a look at the methods NSHomeDirectory and stringByAppendingPathComponent. They might come handy. And it would be very, very useful if you can figure out how to find their documentation.
  4. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    And for the times a complete path isn't needed, something called the working directory is used:

    So how would you discover what the path of the program's current working directory is? Hint: NSFileManager has a method for it.

    Next, how would you tell Xcode to use a specific working directory when running the program? Hint: Xcode has a Help menu with search capabilities. Try searching for working directory.
  5. freeme007 thread starter macrumors regular

    Sep 21, 2008
    Thanks for all the help guys! I was looking for the directory folder where I can put the file so that when xcode runs my program it can detect that file existed.

    I found a code where it will tell me the directory :
    system ("pwd; ls -l");  
    Now when i run
    if([fm fileExistsAtPath:fileName] == NO){
            NSLog(@"File Does Not Exist!");
            return 1;
        }else{ NSLog(@"File Exists!");}
    it gives me the message of File Exists

Share This Page