Get Folder Names of a Collection


for a relatively large API test project (about 1000 requests) i need a generic way to access the folder name of any request in the test scripts. Due to the high effort hard coding the folder names manually is not an option.

I couldn’t find a way to do this. The only thing I found was how to create a collection object (, but this won’t help me unfortunately.

It is possible to get the current request name by using:

What I am looking for is something like: (I know this doesn't exist)

Has anyone any idea how to get the name of the request’s folder?

Hi @henningbertsch!

Outside of creating a Collection object, there isn’t a Sandbox method for getting folder name right now (but we do have an open feature request for it)

How many folders are you dealing with? What about this:

In each folder, add a pre-request script that sets a local variable with the name of the folder. You’d have to hard-code the folder name value, but if you don’t have a ton of folders this could work:

Folder A —> Pre-request script —> pm.variables.set('folder_name','Folder A');

Then, any script in your Collection can access the current folder name by using:

When the Collection run moves to the next folder, that folder would (ideally) contain the same script, but with it’s own value.

1 Like

Hi, sorry for the long delay of my response :wink: have been to vacation.
Your suggested approach did the trick for me. I have added a Pre-Requests-Script to each folder (about 20) and wrote the required info to a temp var.
In my tests I have then used it to write the folder name into the test results like this:

var folderID = pm.environment.get('folderID');
pm.test(folderID, function () {

Thank you for your input :slight_smile: However a native feature still would be great

@henningbertsch Awesome! Glad that worked for you. :slight_smile: Definitely drop a comment on the feature request if it’s something you’d like to see added.