Getting substring in a file path

Hi,

I want to extract a certain substring in my file path. For example, if I have C:\Downloads\Subfolder1\file.pdf and C:\Downloads\Subfolder2\file.pdf then I want to extract Subfolder1\file.pdf and Subfolder2\file.pdf. Is there any way for me to do this?

Hi @upnewbie

Yes. It is possible.

Below is the workflow for the same.
Main.xaml (19.0 KB)

Output :-
image

Mark as solution and like it :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

1 Like

Thank you :slight_smile: Also, is there a way for me to remove the Downloads in this string for example, but keep the other parts? So C:\Subfolder1\file.pdf instead of C:\Downloads\Subfolder1\file.pdf

Have a Look on .net functions and classes
Path

WE do habe Options Like getfilename, …

And The class directoryinfo

Getdirectories

Hi @upnewbie

So the download Keyword will be static always or any other keyword may also der present in the path ??

If its gonna be same all the time then forget the above workflow and do the below thing.

Do all the things inside Assign activity :-

String str = “C:\Downloads\Subfolder2\file.pdf”
str = str.Replace("\Downloads","")

Output :-
image

Mark as solution and like it :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

1 Like

Thank you, that is exactly what I wanted :slight_smile:

Hi @upnewbie

You are welcome :innocent:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Hi

You can use regex, Split, or replace.
For Example:

  1. Split(strinput.ToString,”C:\Downloads\”)(1).ToString.Trim
  2. System.Text.RegularExpressions.Regex.Match(strinput.ToString,”(?<=C:\Downloads).*(\d)”).ToString.Trim
  3. strinput.Replace(“C:\Downloads”,"")
1 Like

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