Pulling From Different Image Folders

If this template helps then use it. If not then just delete and start from scratch.

OS (e.g. Win10):
PsychoPy version (e.g. 1.84.x):
Standard Standalone? (y/n) If not then what?:
**What are you trying to achieve?:

I currently am trying to set my experiment up to grab from different image folders. I was hoping that I could create a code component or something to grab from. i.e. - at the beginning of the experiment PsychoPy would select Image grouping 5 and that would be the images that it draws from for that subject. The next subject would then get selected for image grouping 10, etc.

**What did you try to make it work?:

As of right now I have one main folder with images that are meant to elicit an emotional response. After each image the subject will respond on how the image made them feel. I have made 20 different conditions files that has the specific images for each grouping that I need. Currently, I am switching out different conditions files for each different grouping of images that I have, but I feel like there might be a better way to make this work.

Any help would be appreciated.

Are you running locally? In Python you could add to the Before Experiment tab of a :code: Code component the following:

from pathlib import Path

and then setup a list of folder names as a conditions file for a loop, let’s call the column imgFolder. You could then set the filename of the image to be:

$Path(imgFolder) / myImageFileName

Path takes a string and turns it in to a Path object, which has a lot of handy features like being able to easily add a subfolder using the divide (/) operation and have it use the appropriate slashes for your operating system (annoyingly, Mac and Windows prefer different slashes in file paths…).

If you’re running online, then you may be able to do the same thing with string formatting:

$f"{imgFolder}/{myImageFileName}"

and this should automatically translate to JavaScript as:

`${imgFolder}/${myImageFileName}`

but be wary of the direction of slashes!