Capturing folder information I am getting the full path + file name. I am only wanting the file name

I am capturing filenames in a folder for reporting. I need the file names but the only way i have found to record these is the process attached. but , it gives full path and file name.
I am using this to confirm the amount of files are the same pre and post processing. comparing the two they are all different as the path is different.

How can I get the file name only.Main.xaml (10.0 KB)

Download and use the below activity to extract only the file name from full path -

Regards,
Karthik Byggari

1 Like

but there is no information on how to get the file name only.

You can do this assign activity where “str” is your string:

str = str.Substring(str.LastIndexOf("\"))

This finds the last index of “” and which your file name will assigned to str provided that you give a complete path.

Ok i get it but there is literally just a package and no information what so ever. no activity no information on variables

@kkalian

Did you mean
str = str.Substring(str.LastIndexOf("\"))

You need to type \\ to escape a single backslash.

1 Like

Thank you, yes that^

1 Like

@covcreo
As kkalian said, you can do
str = str.Substring(str.LastIndexOf("\"))

or you can do

str = str.Split("\"c).Last

Both of these take everything after the last backslash, which will give just the file name.

Sorry guys I am really new to this and its kind of incomplete in my mind.

No worries, so to clarify you get the entire path and you need to get just the file name from the path right?

OK I think that I got it now but did I actually need the package that was listed or just str = str.Substring(str.LastIndexOf("\"))

Split or Substring will work well, tis a matter of preference as they both just take everything after the last backslash

OK so just to be sure Am I replacing Directory.GetFiles("\\server1\D_box_1$\A0")
with
str = str.Substring(str.LastIndexOf("\server1\D_box_1$\A0\"))

Sorry I know its going on too long but I am trying to get the hang.

You can use assign activity
FileName= Directory.GetFiles(“your folde path”,"*.fileext")
after that use assign activity
NameOnly= item.Replace(“Your folder path”," ")
Massage box pass the variable nameonly.
Hope you will get your requirements .

I use Directory.GetFiles(Folder).ToList() in a variable list string type and with this i get all names of files in folder.

@covcreo

Try below expression to get the filename.

Eg. varFileName = “C:\Users\RPA\Uipath\Forum.pdf”

fileName = path.GetFileName(varFileName)

If you don’t want extension of the file name then try this.

fileName = path.GetFileNameWithoutExtension(varFileName)

2 Likes

Jesmine

When using the assign with NameOnly= item.Replace(“Your folder path”," ")
I get an item not declared error

any chance you can create a sample main.xml so that I can see what is going on?

@covcreo
See if this helps:
Main.xaml (7.4 KB)

This would work but I am pulling from emails stored in a PST in outlook.