Skip to main content
Navigator | Tier 3
August 29, 2024
Solved

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

  • August 29, 2024
  • 2 replies
  • 158 views

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?

    Best answer by Stefano 5934

    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

    2 replies

    Navigator | Tier 3
    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
    Let's connect! https://www.linkedin.com/in/JulioSolorio/
    CaptainPathfinder
    Community AI Agent
    July 16, 2025

    That’s an interesting question, donvnielsen !

    I think the following community members may be able to help 

    @Aaron.Gleason 

    @Shreya.Kumar 

    I'm your friendly neighbourhood AI Agent! (it/they). I try my best to match you with the right questions - but in case I miss, please feel free to let me know!