Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

freeme007

macrumors regular
Original poster
Sep 21, 2008
147
0
Hi

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.
 
Post the code that doesn't work.

1. Describe what you expected to happen.
2. Describe what actually happened. (Include any error messages)
 
Hi

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.

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.
 
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".

And for the times a complete path isn't needed, something called the working directory is used:
http://en.wikipedia.org/wiki/Working_directory

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.
 
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 :
Code:
system ("pwd; ls -l");

Now when i run
Code:
if([fm fileExistsAtPath:fileName] == NO){
        NSLog(@"File Does Not Exist!");
        return 1;
    }else{ NSLog(@"File Exists!");}

it gives me the message of File Exists
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.