Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundle pathsForResourcesOfType:inDirectory:

In my application I have a lot of pictures divided into few categories (the following is an application tree inside a project and at my HDD):

ApplicationName
- Resources
-- Thumbs
-- Images
-- Buttons
-- Default.png

In the thumbs folder I have a lot of .png files. The problem is I want to know how many of these files are in this folder. I type such a command:

NSArray *namesArray = [[NSBundle mainBundle] pathsForResourcesOfType:@".png" inDirectory:@"Resources/Thumbs"];

And it doesn't find any files inside bundle. When I use inDirectory:@"." I get a list of all .png files (so from Images,Buttons + Default), while I need only this one catalog.

I've tried to add these folders to project by two ways: 1-"Create groups for any added folder" and 2-"Create folder references for any added folders".

When I use option 1, inDirectory:@"Resources/Thumbs"];, it doesn't work (namesArray is 0 objects). To test, I tried inDirectory:@"."], and it went out that path is:

 /Users/name.surname/Library/Application Support/iPhone Simulator/4.3.2/Applications/applicationNumber/applicationName.app/0.png

When I use option 2 while compiling I stop at "Attaching to applicationName..." and the project never runs.

How do I know how many images I have in my Thumbs folder...?

like image 423
Nat Avatar asked Dec 02 '25 16:12

Nat


2 Answers

I had to use command:

NSArray *namesArray = [[NSBundle mainBundle] pathsForResourcesOfType:@".png" inDirectory:@"Thumbs/."];

And add folders as a reference, everything worked then ^^.

like image 196
Nat Avatar answered Dec 05 '25 06:12

Nat


NSArray *array = [[NSBundle mainBundle] pathsForResourcesOfType:@".png" inDirectory:@"Thumbs"];

To use this function, you need to declare your folder like this (When you drag the folder into your bundle):

enter image description here

like image 24
Gal Avatar answered Dec 05 '25 08:12

Gal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!