How to combine file paths in UiPath Studio
Combining paths is an essential operation of almost every workflow, yet there is no System activity dedicated to combining paths in UiPath Studio. So in this blog post we will explore the only correct way to combine two strings into a path.
Many people resort to string concatenation like in the expression below:
folderPath + "/" + fileName
This can lead to several issues:
- the path will be invalid if the
folderPath
already contains a trailing/
- if this is a cross-platform activity, it is important to consider that not all the operating systems use
/
(forward slash) for the path separator, there are some (Unix-based systems) which use a\
(backslash). This expression would result in an invalid path on such system.
Always use Path.Combine
instead of string concatenation.
Path.Combine(rootFolder, logoFileName)
Path.Combine
takes in a params string[] paths
, so you can give it as many path segments as you’d like to combine. For example:
Path.Combine(rootFolder, mediaFolderName, imagesFolderName, logoFileName)