The above comment of CodaFi is great, Also the samething if you want to do you can do like this below. Though i have removed this line. if its required. NSArray* cacheDirectory = [fileManager contentsOfDirectoryAtPath:[pathURL absoluteString] error:nil];
So that you can directly fetch the name of file as a string inspite of an array, :-
NSFileManager* fileManager = [[NSFileManager alloc] init];
NSArray* urls = [fileManager URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask];
NSArray* directory = [fileManager contentsOfDirectoryAtURL:urls[0] includingPropertiesForKeys:@[@"NSCreatingDateKey"] options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];
NSLog(@"%@", directory);
NSURL* pathURL = [[urls objectAtIndex:0] URLByAppendingPathComponent:@"stanfordpictures/"];
if ([directory count] < 3) {
[fileManager createDirectoryAtURL:pathURL withIntermediateDirectories:NO attributes:nil error:nil];
}
NSString* pictureString = @"hussain_2156.pptx";//[NSString stringWithFormat:@"picture%d.png", self.cacheCounter];
NSURL* pictureURL = [pathURL URLByAppendingPathComponent:pictureString];
NSLog(@"%@", pictureURL);
NSData *cacheImageData = [NSData dataWithContentsOfFile:@"/Users/hussain/Desktop/hussain_2156.pptx"];
if ([cacheImageData writeToURL:pictureURL atomically:YES])
{
NSLog(@"It worked");
NSString *file=nil;
NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtPath:[pathURL path]];
while(file =[dirEnum nextObject])
{
NSLog(@"%@",file);
}
}
else
{
NSLog(@"An error occurred");
}