How to manipulate a string in a file Path

Hi,

I have this file path: C:\Users\carla-89\Downloads\convocatoria.xls (‘ExcelPath’ variable)

And I want to substract “convocatoria.xls” because each file i will wanna download will have a different name file. I try do:
StrExcelPath = ExcelPath.ToString
StrSplitExcelPath = StrExcelPath.split(""c).ToString

and then StrSplitExcelPath(4)

And only output and ‘e’.

What i need to do to extract only ‘convocatoria.xls’?

Hi @Carla_Munoz

Try this for without extension:
filename = System.IO.Path.GetFileNameWithoutExtension(“path”)

For with extension:
filename = path.GetFileName(“path”)
or
filename = System.IO.Path.GetFileName(“path”)

Regards,

1 Like

@Carla_Munoz
Try this

path.GetFileName(ExcelPath)

this will give you file name with extension

1 Like

HI @Carla_Munoz

How about this expression?

filename =Path.GetFileName(“C:\Users\carla-89\Downloads\convocatoria.xls ”)

Regards
Gokul

1 Like

@Carla_Munoz ,
If you want to get the filename with extension you can use

FileName= Path.GetFileName("FilePath")

Regards,

1 Like

hi @Carla_Munoz
Split(ExcelPath.tostring,“Downloads\”)(1)

1 Like

Hi @Carla_Munoz
Try this using split function

1 Like

Hello, what type of variable is FileName because is giving me an error

@Carla_Munoz

The filename variable is a “String” type

1 Like

@Carla_Munoz Its Type will be string type. It will return String

1 Like

Hi @Carla_Munoz

You can use the Split function to split the output. Split by using "".

- Assign -> StrFileName = StrExcelpath.Split("\").Last

Hope it helps!!

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