I personally would not use the scalar functions referenced in the above link because scalar functions slow things down. Inline Table Values functions (itvf) are the way to go. It should not matter much in this case because you're likely not dealing with many rows but, for a high-performing alternative to scalar UDFs have as look at this article: http://www.sqlservercentral.com/articles/T-SQL/91724/.
For sys.database_files you can just do this:
WITH prep AS
(
SELECT physical_name, li = LEN(physical_name)-CHARINDEX('\',REVERSE(physical_name))
FROM sys.database_files
)
SELECT fpath = SUBSTRING(physical_name,1,li), fname = SUBSTRING(physical_name,li+2,8000)
FROM prep;
Here's an re-usable alternative to scalar udfs for this kind of thing:
-- A high-performing, re-usable itvf to split a string on the last delimiter.
CREATE FUNCTION dbo.itvf_getfilename (@fullname varchar(255), @delimiter char(1))
RETURNS TABLE AS RETURN
SELECT fpath = SUBSTRING(@fullname,1,li),
fname = SUBSTRING(@fullname,li+2,8000)
FROM (VALUES (LEN(@fullname) - CHARINDEX('\',REVERSE(@fullname)))) prep(li);
Here's a usage example:
DECLARE @fullname varchar(255) = 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLSERVER2014X64\MSSQL\DATA AjbTest.mdf';
SELECT fpath, fname FROM dbo.itvf_getfilename (@fullname,'\');
... and, against a table:
SELECT fpath, fname
FROM sys.database_files dbf
CROSS APPLY dbo.itvf_getfilename(dbf.physical_name,'\');