Getting Images List using bundle - iphone

I am using this code to get the list of Images in my project
NSArray *pngPaths = [[NSBundle mainBundle] pathsForResourcesOfType:#"png" inDirectory:nil];
I dont want to get one image from the list can i add filter to it
Thank You

I think it is easier to do when you already load all paths into your memory NSArray. You can just loop over all elements and examine the path and remove paths you don't want

Related

Obtaining files from group with pathsForResourcesOfType

I have a group called initialdata in my main bundle containing 7 JPG's. From what I've read the code below should give me an array with all the JPG's located in that group but the array is always 0. What could be the problem?
NSArray *namesArray = [[NSBundle mainBundle] pathsForResourcesOfType:#"jpg" inDirectory:#"initialdata"];
NSLog(#"namesarraycount=%i",namesArray.count);
Are you sure you created folders instead of creating just group? You have to make sure that you created physical folders and subfolders. The above command should work after that.

NSBundle returns nil

I wanted to read version information of my application from the plit file.
For this I am using a code as shown below.
NSString *myFilePath = [[NSBundle mainBundle]
pathForResource:#"MyApp-Info"
ofType:#"plist"];
// Format output
NSLog(#"%#",myFilePath);
The output
2010-08-31 17:14:10.095 MyApp[8759:20b] (null)
It always returns nil even if I tried to Import an existing file of type, text.txt still return nil, where text.txt is imported in the application.
I have goggled for the problem dont every one recommends to use NSBundel to read an pre imported file, but no use.
Any help, or an better way to read application version.
Got the solution via another link in the stack overflow here.
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleVersion"];
NSLog(#"%#",version);
The reason this doesn't work is because pathForResource looks for stuff inside "MyApp.app/Contents/Resources". The Info.plist file does not reside inside the resources folder, so it's going to return nil if you look for it there. The correct way to get at it is to use the "infoDictionary" method on NSBundle.

NSBundle and Accessing Folder inside Resources Folder

I have Images folder inside the Resources folder which contains images. I am using the following code to access the images but the resultant array always comes out to be empty:
NSArray *imagesPath = [bundle pathsForResourcesOfType:#"gif" inDirectory:#"Images"];
Am I missing something??
If you do [[NSBundle mainBundle] pathForResource:#"Images" ofType:nil] do you get the correct path for that folder?
If not are you sure that is a folder and not a simple group?

Populate table view with filenames

Is there a way to populate the data in a table view with the filenames from a certain folder?
Thanks.
NSFileManager's documentation has a section under Tasks called 'Discovering Directory Contents'. Use these methods to get the contents of a directory and then populate your data source for the table view with the results.
You can use that data to display the directory contents in the table view.
This is the code I used (for anyone that may need it):
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSArray *dirContents = [[NSFileManager defaultManager] directoryContentsAtPath:bundleRoot];

Problem with reading data from plist in the iPhone SDK

I'm creating a myDb.plist file in my resources folder and trying to read it, but it's not getting read. I'm using the following code.
NSString* plistPath = [[NSBundle mainBundle] pathForResource:#"myDb" ofType:#"plist"];
contentArray = [NSArray arrayWithContentsOfFile:plistPath];
contentArray is showing null.
What can I try to resolve this?
Make your plist data array and not dictionary. Dictionary also works but i tried with hit and trial. Also, print NSLog your data, if in case you need, to check the input from plist.