Separate File path from File name

C:\Users\TEST\Documents\UiPath\VacWeek\ExcelFile 1.xlsx

how can i split this file path so that i get file name in one variable and path in one variable.

Hi @Latif

Please try this method.

path.GetFileNameWithoutExtension("C:\Users\TEST\Documents\UiPath\VacWeek\ExcelFile 1.xlsx")

Feel free to reach us at any time if you have doubts. Thanks.

Happy Automation

1 Like

you can try with Path.GetFilename(“C:\Users\TEST\Documents\UiPath\VacWeek\ExcelFile 1.xlsx”).ToString

And how I can get path to another variable I have both seprated.


Another file from the same path from 'C:\Users\TEST\Documents\UiPath\VacWeek'?

No act… when file is selected the path and filename is together in one variable.
And i want to seprate… file name in one and path in one means
path should be in ExcelFilePath Vairable
Name should be in ExcelFileName variable

the solution you gave first is perfekt that i got my file name in ExcelFileName variable but how can i store the path I did split from in another variable.

Another way is to use the Split(YourPath, “/”) and this will give you list. from this list your last item will be your fileName and the rest of items you can combine to get the file path.

Okay. You can store like below,

  1. Drop Assign activity and create a variable(variable type - string)
  2. Assign the value like, splitingVariable(Index of the path).

Note: SplitingVariable is which you split the path from another variable

For Example:
If your string like this “Hey, this is my path C:\Users\TEST\Documents\UiPath\VacWeek\ExcelFile 1.xlsx”. And you are splitting it by space(" "). Then the index of the path is ‘5’


oh there is not a way we can do with Path.GetFilename(“
and get only path out from file name

This is what you are looking for:

To store the path in variable you should use split function. @Latif

Since, we can’t get the path of the file by function.



Actually there is, I have already put the function he needs to get only the folderpath of a file.

Hi @dimibot

Actually @Latif wants to separate the file name and file path, and assign them in two separate variables. Thanks.


Let’s take his example:
If there is one variable (string) named FilePath with value:
“C:\Users\TEST\Documents\UiPath\VacWeek\ExcelFile 1.xlsx”

Path.GetFilename(FilePath ) → “ExcelFile 1.xlsx”
Path.GetFileNameWithoutExtension(FilePath) → “ExcelFile”
Path.GetDirectoryName(FilePath) → “C:\Users\TEST\Documents\UiPath\VacWeek”

There is no need to use a split function when working with paths.

1 Like

Small error in your reply. File name without extension is “ExcelFile 1”
Otherwise, yours is the correct way using the Path methods. One should never use split to decompose a path as there are too many special cases you might have to code for.