How to get a File name from a complete File path

When using a FileOpen or FileList control in Linx, and you receive a Full File Path, in some instances you’d like to extract the File name from the File path. Thus you can use an SQL query, with the input of the Full path:

DECLARE @full_path varchar(max)
Select @Full_Path = @{OpenGenerateFile.File.FilePath}

SELECT  LEFT(@full_path, LEN(@full_path) - CHARINDEX('\', REVERSE(@full_path))) as NameOfFolder,
        RIGHT(@full_path, CHARINDEX('\', REVERSE(@full_path)) - 1) as NameOfFile

For example, if {OpenGenerateFile.File.FilePath} was “C:\Linx\BB\Export.csv” then the result will be:

NameOfFolder: “C:\Linx\BB”
NameOfFile: “Export.csv”

You can also use the Linx RegularExpression function. To get the filename from the full path use something like (?<=\)[^\]+$ . The filename is then available to all other Linx functions that are in scope.

We have a story in our backlog that adds functionality to the Linx Expression Editor to manipulate paths. The idea is to have something like =$.FilePath.GetFileName(FullPathHere) extract the path.

Thank you Gawie, this works great. I’ve done a quick solution to use it:

The result: