← All how-to recipes

How to extract the file name from a path or URL

✓ Verified in LibreOffice 25.8.7.3

Get just the file name (or last segment) from a path or URL — clean up import logs, links, and directory listings.

The formula

AppFormulaNotes
Excel=TRIM(RIGHT(SUBSTITUTE(A2,"/",REPT(" ",200)),200))For Windows backslash paths, replace "/" with a backslash. Excel 365: =TEXTAFTER(A2,"/",-1).
Google Sheets=TRIM(RIGHT(SUBSTITUTE(A2,"/",REPT(" ",200)),200))Identical; or =REGEXEXTRACT(A2,"[^/]+$").
LibreOffice Calc=TRIM(RIGHT(SUBSTITUTE(A2,"/",REPT(" ",200)),200))Identical.

How it works

The last-word trick pointed at the path separator: SUBSTITUTE pads every "/" to 200 spaces so the final segment sits alone in the rightmost 200 characters, RIGHT grabs it, and TRIM cleans up — "docs/2026/reports/report.xlsx" yields "report.xlsx". Swap "/" for a backslash to handle Windows file paths. On modern versions TEXTAFTER(A2,"/",-1) does it directly (the -1 means after the LAST separator). To then drop the extension, apply the same idea to the "." with LEFT/FIND.

Verified, not just documented

We ran =TRIM(RIGHT(SUBSTITUTE(A2,"/",REPT(" ",200)),200)) in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned report.xlsx — exactly the expected result. Every formula here is confirmed by actually executing it.