Skip to main content

What is the best implementation for dividing a file name string into its folder, file name, and extension components. I haven’t found a package that takes a string and parses it. Am I missing something?

I’ve written a utility bot to do it by reversing the string and looking for the first period and first slash to accomplish what I want. However, it feels sloppy in what it does.

I’ve looked at calling out to javascript, but that doesn’t have all-in-one solution.

Also, any chance there will be a powershell package like there is javascript and vba?

You can use this package to run any script and capture the response: 
Run Synchronous Scripts Package - Bot Store (automationanywhere.com)
 

This is how it’d look inside a task bot.

 

And here’s the code in the image:

PS C:\> :System.IO.Path]::GetFileNameWithoutExtension('$str_filePath$')

You can find more functions in the following link: 

https://learn.microsoft.com/en-us/dotnet/api/system.io.path

Additional examples:

PS C:\> CSystem.IO.Path]::GetExtension('$str_filePath$') # Returns  .xlsx
PS C:\> CSystem.IO.Path]::GetDirectoryName('$str_filePath$') # Returns  F:\Test

Reply