Saturday, February 11, 2012

Explore the files in the directory; determine if the file exists in directory




//explore the files in directory
- (void)viewDidLoad
{

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [paths objectAtIndex:0];
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSLog(@"Documents directory: %@", [fileManager contentsOfDirectoryAtPath:documentDirectory error:nil]);
}

// determine the file exists in the directory

-(NSString *)dataFilePath
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [paths objectAtIndex:0];
    return [documentDirectory stringByAppendingPathComponent:data.plist];
}

- (void)viewDidLoad
{

        NSString *filePath = [self dataFilePath];
    
        if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
        {
            NSMutableArray *database = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
            
            other code...

        }

        [super viewDidLoad];
}


No comments:

Post a Comment