0

I am trying to build simple tests to see if files I need (images, videos, audio files) are in my app. Whenever I try to do something such as:

if (![[NSFileManager defaultManager] fileExistsAtPath:@"Menu Loop.mp3"])
{ 
    STFail(@"File does not exist");
}
else
{
    NSLog(@"Passed");
}

It says the file does not exist. I can see the file is there, and I know it is failing because the file in the app folder and not in the test folder. Is there a way of getting out of the test folder to test if the files exists without adding all of the files to the test folder? I have tried doing something such as fileExistsAtPath:@"../appfolder/Menu Loop.mp3" to try to navigate out of the test folder, but it unfortunately does not work that way either.

Thanks in advance!

Will
  • 1,697
  • 17
  • 34

1 Answers1

0

You cannot directly access folders like that through the iOS SDK. You must save and read files using the system functions that return the proper path:

NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
NSString *pathToMenuLoopFile = [rootPath stringByAppendingPathComponent:@"Menu Loop.mp3"];

If you are looking to load files that you include in your Xcode project, please take a look at this post: Loading data files in iPhone project

Community
  • 1
  • 1
rosslebeau
  • 1,283
  • 6
  • 6