How to extract filename from full path in Excel?

In Excel, we can extract the filename from the full path with several methods. This article will introduce some methods for you.


You can use the following syntax to extract the filename from a full file path in Excel:

=TEXTAFTER(A2, "", -1)

This particular formula extracts the filename from the full file path in cell A2.

For example, suppose cell A2 contains the following full file path:

  • C:UsersbobDocumentscurrent_databaseball_data.xlsx

This formula will return:

  • baseball_data.xlsx

The following example shows how to use this formula in practice.

Example: Extract Filename from Full Path in Excel

Suppose we have the following column of full file paths in Excel:

Suppose we would like to extract only the filename from each file path in column A.

We can type the following formula into cell B2 to do so:

=TEXTAFTER(A2, "", -1)

We can then click and drag this formula down to each remaining cell in column B:

Excel extract filename from path

 

How This Formula Works

The TEXTAFTER function in Excel extracts all text in a cell after a specific character or substring.

This function uses the following syntax:

TEXTAFTER(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])

where:

  • text: Text to search
  • delimiter: Character or substring to extract text after
  • instance_num (optional): Instance of delimiter after which to extract text (default is 1)
  • match_mode (optional): 0 = case-sensitive (default), 1 = case-insensitive
  • match_end (optional): Treat end of text as delimiter (disabled by default)
  • if_not_found (optional): Value to return if delimiter is not found

Recall that we used the following syntax to extract the text after the last space in a cell:

=TEXTAFTER(A2, "", -1)

By using a value of -1 for the instance_num argument, we were able to specify that we wanted to extract the text after the last instance of a slash.

This is equivalent to extracting just the filename from the path, since the filename occurs after the last slash in the string.

Note: You can find the complete documentation for the TEXTAFTER function in Excel .

x