Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] List all files in the file pool in an inline script

edited October 2014 in OpenSesame

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

  • edited 4:00PM

    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 its listdir(<path>)-method to get a list with all files in the directory.

    Does this help?

    Eduard

    Buy Me A Coffee

  • edited 4:00PM

    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

  • edited 4:00PM

    Actually, I just realized the answer to my second question. I saw that the experiment has an experiment_path field that contains the experiment directory so now I can get all files there by simply doing:

    import os
    print os.listdir(exp.experiment_path)
    

    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.

  • edited October 2014

    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 os module 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:

    1. Check if the file is in the file pool (subfolders not supported).
    2. If not, check if the file is in the experiment folder.
    3. If not, check if the file is in the "fallback-pool folder" (mostly for versioning, see here).
    4. If not, assume that the file is either absolute or relative to the current working directory.

    Eduard

    Buy Me A Coffee

  • edited 4:00PM

    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_path to discover what files there are.

    Mitko

  • edited October 2014

    Alright then.

    By the way, I just found out how to get the path of the file pool.

    It is also part of the experiment and you can access it by typing self.experiment.pool_folder. (big surprise...)

    I guess that's all you need?

    Eduard

    Buy Me A Coffee

  • edited 4:00PM

    Oh, I saw pool_folder in the documentation but I thought it was used only for input. I should have tried it, I feel stupid now :)

    That'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.

Sign In or Register to comment.