Very basic file reading question - where is the data directory?

I am trying to figure out how to access files. All the documentation I’ve seen says that loadImage() etc will only work on files in the data directory. (It seems very strange, that I can’t give an absolute pathname… but hey, ok.)

But…where is the data directory? I set up a test sketch and before I named it, it lived in a very long named place which would be super awkward to access for popping input files into it.

So I named it something sensible by doing Save. Now I can find its path by doing Sketch/ShowSketchFolder, and it looks like this:

But there’s no data directory in it. I’ve been looking at the Reference documentation and Tutorials and stack overflow and this forum for a very long time (…a few hours) and I am totally stuck. If input can only come from a data directory - where is this directory? Do I need to create it for each sketch?

This must be very simple. Can someone advise?

It’s automatically created when we drop a media type file onto the PDE.

We can access it via methods dataPath() and dataFile():

1 Like

Yeah, the data folder…

You can create it by hand in your Sketch folder

Each Sketch has its own data folder to store images etc.

See reference for dataPath() and sketchPath()

1 Like

Thanks for the help.

When you talk about “drop a media type file onto the PDE” - I don’t understand what you mean. What kind of operation is this? Is it an “outside Processing” operation? Do you literally mean drag and drop a file while looking at the sketch directory in Finder (I’m on a Mac)? Or do you drop a file onto the code editing window (rather strange… but… )? etc

Thanks also for the help. When you say I “can” create it by hand - do you mean I “must” create it by hand? Is that how it’s intended to work?

What’s confusing me is that the documentation says that each Sketch “has” its own data folder. But I don’t see one when I look at a sketch in its containing folder. It doesn’t seem to “have” it. And it’s not obvious how to create it - it’s not obvious whether that’s something you do inside Processing somehow, or just in the normal file system (which seems clunky), or as the other poster suggested, by somehow “dropping” the file somewhere, somehow.

I think it’s one of those things that when you see it once it seems obvious afterwards.


You can also make the folder by hand and copy into it what you need


Indeed, the data folder is not there automatically.

You can create it by drag and drop an image or mp3 (I guess) onto the IDE / editor.

(Like you can drop a jar file to generate the code folder. Never mind.)

But you can create the data folder also by hand.

Besides: hit ctrl-k (in processing, the IDE or PDE, the Editor, all the same thing) to open the Sketch folder. Simple but I use it all the time.



I think it works in Sketch folder itself too but that’s kind of a bug or feature. Better use the data folder.

Just found this::::

A sketch folder sometimes contains other folders for media files and other code. When a font or image is added to a sketch by selecting “Add File…” from the Sketch menu, a “data” folder is created. Files may also be added to your Processing sketch by dragging them into the text editor. Image and sound files dragged into the application window will automatically be added to the current sketch’s “data” folder. All images, fonts, sounds, and other data files loaded in the sketch must be in this folder.


Of course you can! Try it with… dunno on an mac, on win it’s just c://hello//…

Besides look at selectFolder command in the reference to get a dialog box to select a folder in your Sketch (while your Sketch runs, that’s not the IDE)

1 Like
  • By default Processing looks for a filename at the sketchPath() 1st.
  • Only if it doesn’t find it there it looks at dataPath().
  • By default Processing saves everything on the sketchPath().
  • Wrap a filename on dataPath() in order to save it on subfolder “data/”.

An example sketch using dataFile() + listPaths():


See also here Adding images with absolute paths

1 Like