Skip to main content
Question

Parse string into file name elements path, file name, and extension

  • August 29, 2024
  • 1 reply
  • 36 views

Forum|alt.badge.img+3

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?

1 reply

Forum|alt.badge.img+5
  • Navigator | Tier 3
  • 36 replies
  • August 30, 2024

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:\> [System.IO.Path]::GetExtension('$str_filePath$') # Returns  .xlsx
PS C:\> [System.IO.Path]::GetDirectoryName('$str_filePath$') # Returns  F:\Test

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings