[solved] List all files in the file pool in an inline script
Hi, I'm new to OpenSesame and want to use it for an experiment.
I'd like to make my OpenSesame project somewhat generic and driven by the files that are in the file pool. For this I need to get a list of all files in the pool, but could not find a way to do this so far. The 'experiment' object in python only has methods to get a known file. I saw a forum post that says all files in the pool are extracted to a temporary directory but I do not know where it is.
How can I get a list of all the files in the pool?
Comments
Hi Mitko,
Welcome to the forum!
One way to do this is following. If you open the file pool, you see this little brownish cardbox/folder icon. Click on it and the directory of the file pool on your system will be opened. From there you can obtain its path.
Next, you can import the python os library in an
inline scriptand use itslistdir(<path>)-method to get a list with all files in the directory.Does this help?
Eduard
Hi Eduard,
Thanks for your suggestion. That would work, but only on my computer. If I give the project to someone else, they will not be able to just run it.
OpenSesame must know internally where the pool directory is. Isn't there a way to just get the path directly from the tool?
Alternatively, if I understood this correctly, it is possible to use the project's directory instead of the internal pool. Is there a way to find what the project directory is within python?
Mitko
Actually, I just realized the answer to my second question. I saw that the experiment has an
experiment_pathfield that contains the experiment directory so now I can get all files there by simply doing:I will use this for now, but I am still interested whether I can get the file pool directory somehow from OpenSesame. I would prefer to package all my experiment data together with the project.
True, this wouldn't work if you want to use the same script and different machines.
Well, in this case, you can try to work around the file pool at all.
For example, place all your files in a folder, use the
osmodule to get the all the file names, then loop over and concatenate them with the path to that folder. In doing so, you get the absolute path for each file and can use them as if they were in the file pool.If you place all your files in the directory, where your experiment is located, you can also access them directly. As Sebastiaan pointed out in another thread:
The logic of filename resolution is as follows:
Eduard
Thanks for the help. As you suggest, I will go around the file pool entirely. I will place the files in the project directory and use the
experiment_pathto discover what files there are.Mitko
Alright then.
By the way, I just found out how to get the path of the file pool.
It is also part of the
experimentand you can access it by typingself.experiment.pool_folder. (big surprise...)I guess that's all you need?
Eduard
Oh, I saw
pool_folderin the documentation but I thought it was used only for input. I should have tried it, I feel stupid nowThat's precisely what I needed, thanks a lot for this and for answering so quickly!
Mitko
P.S. Since I'm new, I don't know what's the proper way to mark this issue as resolved. Let me know if I need to do something.