environment.CurrentDirectory - specific part

Hi All,

Im trying to take the project name from CurrentDirectory
When I run a process from the studio
environment.CurrentDirectory looks like C:\Users\BOTname\Desktop\ProjectName
so I have


However when I run a process from the Orchestrator
environment.CurrentDirectory look like C:\Users\BOTname\.nuget\packages\ProjectName\1.0.7214.6145\lib\net45

How can I adjust my assign to have ProjectName instead on net45

Thank you

Hi
Maybe I should add, once there is
C:\Users\BOTname\.nuget\packages\ProjectName\1.0.7214.6145\lib\net45
BOTname and ProjectName and package version is always different. I’m not sure if your solution will work

You could also chance the .Last to (5) to get the ProjectName but that only works if the directory structure stays like:
C:\Users\BOTname\.nuget\packages\ProjectName\1.0.7214.6145\lib\net45

Hello @niteckam
I thought the Project Name is constant
Try this code

System.Text.RegularExpressions.Regex.Match(YourdirectoryVariable,".+(?=\\\d+\.\d+\.\d+\.\d+)|.+(?=\\\d+\.\d+)").ToString

@vickydas

Hi Better
But I receive output
C:\Users\BOTname.nuget\packages\ProjectName

Hi @tbrinkman
If I only change Last to (5) then I have the error
Assign | ConfigFileName: Index was outside the bounds of the array.

What exactly do you need ?

If you just want the file name use this pattern

System.Text.RegularExpressions.Regex.Match(YourdirectoryVariable,"\w+(?=\\\d+\.\d+)").ToString

this suprises me, I was expecting this:

The error sugests that split does not result in 6 or more parts,

for your local setup that is correct (“C:\Users\BOTname\Desktop\ProjectName” has only 5 parts) but for the production envirorment the path should contain more than 6 parts

@tbrinkman

Here we need to set up the variable type?

the erro comes from the “\c” instead of the ""c
but in the end you would have to change the (5) every time you would switch directory structure (or dev to prod) so I am glad vickydas solution worked

Hello @niteckam if project name is all you need then why not to refer the project json file, located in project folder itself.
just read Project.json to string variable

ReadTextFile = "/project.json" -- output > strProjectInfo
Log message = Newtonsoft.Json.Linq.JObject.Parse(strProjectInfo).Item("name").ToString

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.