SQL query output on one line
Turning rows into columns known as a PIVOT operation. There are several ways to implement this operation, including a built-in expression. The simplest to understand, and most flexible, I find to be the CASE construct.

I'll use an in-line CTE to wrap your query. There's no magic here, it's just a convenient way of using your existing code. I've added column type_desc to help distinguish the source of each amount. The built-in function DB_NAME() is used to give a "key" value to the output.

;with YourData as
(
    select
        DBName = DB_NAME(),
        type_desc,
        [Name],
        physical_name [Path],
        CAST(size AS BIGINT)*8192 [TotalBytes], 
        CAST(FILEPROPERTY(name,'SpaceUsed') AS BIGINT)*8192 [UsedBytes], 
        (case when max_size&lt;0 
             then -1 
             else CAST(max_size AS BIGINT)*8192 end) [MaxBytes]
    from sys.database_files
)
select
    DBName,
    RowsTotalBytes = sum(case when type_desc = 'ROWS' then TotalBytes end),
    LogTotalBytes  = sum(case when type_desc = 'LOG' then TotalBytes end)
from YourData
    group by DBName;


The values we want occur in your query as two rows in a single column. The CASE expressions separate them into individual columns, with a NULL in the other column, still in two rows. By grouping I collapse the two rows into as single row. Hence the purpose for introducing DB_NAME().

Using SUM() serves two purposes: it returns a single value for all files of a type and ignores the NULL introduced for the other type_desc.

If you have multiple data or log files and want a separate output value for each use Name in the when instead of type_desc.