# Opening assets inside folders

**URL:** https://discourse.processing.org/t/opening-assets-inside-folders/35010
**Category:** Coding Questions
**Created:** [February 6, 2022, 4:21pm UTC](https://discourse.processing.org/t/opening-assets-inside-folders/35010 "2022-02-06T16:21:45Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JoseMY](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josemy/32/2016_2.png) [@JoseMY](https://discourse.processing.org/u/JoseMY)
#### Post date: [February 6, 2022, 4:21pm UTC](https://discourse.processing.org/t/opening-assets-inside-folders/35010/1 "2022-02-06T16:21:45Z")

</div>

Hi!  
I’m doing a big project using processing. I have a bunch of files containing assets, and I want to store them in  
data folder/font\_assets  
data folder/sprite assets  
etc.

But when I try to load them, everything fails. I’ve tried the following:

```auto
String path="assets_fonts/";
  FFont=loadImage(path+"nokia_font_dark_strip.png");

```

This did not work. Then I tried replacing “/” with File.separator:

```auto
String path="assets_fonts"+File.separator;
  FFont=loadImage(path+"nokia_font_dark_strip.png");

```

That didn’t work. So I first tried prefixing path with “.” and, as a second chance, with dataPath():

```auto
String path=dataPath(File.separator)+File.separator+"assets_fonts"+File.separator;
  FFont=loadImage(path+"nokia_font_dark_strip.png");

```

Everytime I get this message:

The file (blah, blah) is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.  
File path is always an existing path that contains the file I’m looking for.

¿Any suggestion on how to access the file? ¿Should I gave some permission or something? I’m using Processing IDE for Windows.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [February 6, 2022, 4:34pm UTC](https://discourse.processing.org/t/opening-assets-inside-folders/35010/2 "2022-02-06T16:34:10Z")

</div>

[**dataPath()**](http://processing.github.io/processing-javadocs/core/processing/core/PApplet.html#dataPath-java.lang.String-)

> [@Save image by input name as jpg or to absolute path](https://discourse.processing.org/t/save-image-by-input-name-as-jpg-or-to-absolute-path/8674/3):
>
> Pass the filename’s String as an argument for dataPath(): open_file_folder partialSave.save(dataPath(line));

> [@Weird issue with pgraphics](https://discourse.processing.org/t/weird-issue-with-pgraphics/2063/4):
>
> /\*\* \* PGraphics arrayCopy() (v1.1) \* GoToLoop (2018/Jul/25) \* Discourse.Processing.org/t/weird-issue-with-pgraphics/2063/4 \*/ static final String FILENAME = "balls.", EXT = ".jpg"; static final String FC = "Frames: ", SC = " - Shots: "; static final int BALLS = 200, DIAM = 20, RAD = DIAM \>\> 1; PGraphics left, right; void setup() { size(640, 480); left = createGraphics(width \>\> 1, height); right = createGraphics(width \>\> 1, height); left.beginDraw(); left.background((color) …

> [@Save variable in a loop](https://discourse.processing.org/t/save-variable-in-a-loop/4654/4):
>
> /\*\* \* Load & Save Variable (v1.0.1) \* GoToLoop (2018/Oct/20) \* https://Discourse.Processing.org/t/save-variable-in-a-loop/4654/4 \*/ int a; void setup() { size(300, 200); noLoop(); fill(-1); textAlign(CENTER, CENTER); textSize(0100); final String[] aFile = loadStrings("a.txt"); if (aFile != null) a = int(aFile[0]); } void draw() { background((color) random(#000000)); text(a, width\>\>1, height\>\>1); } void mousePressed() { ++a; redraw = true; } @Override void exit()…

> [@Iterate throw JSON array values](https://discourse.processing.org/t/iterate-throw-json-array-values/1710/3):
>
> /\*\* \* JSON to CSV (v1.3) \* GoToLoop (2018/Jul/12) \* https://Discourse.Processing.org/t/iterate-throw-json-array-values/1710/3 \*/ JSONObject json = loadJSONObject("data.json"); JSONObject facets = json.getJSONObject("facet\_counts").getJSONObject("facet\_fields"); JSONArray jsonArr = facets.getJSONArray("structHasAuthIdHal\_fs"); Table t = new Table(); int[] colTypes = { Table.STRING, Table.STRING, Table.STRING, Table.INT }; t.setColumnTypes(colTypes); for (int size = jsonArr.size(), i = 0; i…

---

<div class="post-metadata">

### Author: ![JoseMY](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josemy/32/2016_2.png) [@JoseMY](https://discourse.processing.org/u/JoseMY)
#### Post date: [February 7, 2022, 7:05am UTC](https://discourse.processing.org/t/opening-assets-inside-folders/35010/3 "2022-02-07T07:05:31Z")

</div>

Hi, @GoToLoop .

Thanks for your reply, but the threads you show do not seem to answer my question. They are all examples of either file saving or opening of files in the data folder, not subfolders of it.

I’m unsure the problem resides in dataPath() function, since the file I’m opening is not inside dataPath, but in a subfolder of it.

Here are some other failed options:

Option a:

```auto
String path=dataPath("assets_fonts")+File.separator;
FFont=loadImage(path+"nokia_font_dark_strip.png");

`/* Result: The file "C:\Users\JOSE\Documents\Processing\doorsanddrawers\data\assets_fonts\nokia_font_dark_strip.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.`
*/

```

Option b:

```auto
  FFont=loadImage(dataPath("assets_fonts"+File.separator+"nokia_font_dark_strip.png"));

/* Result: The file "C:\Users\JOSE\Documents\Processing\doorsanddrawers\data\assets_fonts\nokia_font_dark_strip.png" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
*/.

```

Option b:

```auto
  FFont=loadImage(dataPath("assets_fonts"+File.separator+"nokia_font_dark_strip.png"));

```

In both cases, the file name and path is OK, but processing can’t access the file.

The only solution I found was moving the file to the dataPath (i.e. not a subfolder of it) and using a simple:

```auto
  FFont=loadImage("nokia_font_dark_strip.png");

```

Is this some result of java sandboxing?

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [February 7, 2022, 7:15am UTC](https://discourse.processing.org/t/opening-assets-inside-folders/35010/4 "2022-02-07T07:15:03Z")

</div>

Function **dataPath()** also accepts relative paths w/ subfolders.

If you have a subfolder called “images/” inside sketch’s folder “data/” and a filename called “nokia\_font\_dark\_strip.png” there, you just concatenate both as 1 argument for **dataPath()**:

```auto
static final String
  IMAGE_SUBFOLDER = "images/",
  IMAGE_FILENAME = "nokia_font_dark_strip.png";

PImage img;

void setup() {
  img = loadImage(dataPath(IMAGE_SUBFOLDER + IMAGE_FILENAME));
}

```

P.S.: Actually, for loading functions, **dataPath()** isn’t necessary. Just use it for saving-type functions:

```auto
static final String
  IMAGE_SUBFOLDER = "images/",
  IMAGE_FILENAME = "nokia_font_dark_strip.png";

PImage img;

void setup() {
  img = loadImage(IMAGE_SUBFOLDER + IMAGE_FILENAME);
}

```
