Skip to main content

Extract file name from a file path


Robbert van Tongeren
Thinkwise blogger

Goal

Sometime you need to extract only the file name (or maybe extention) from a file path.

Solution

declare @file_path varchar(500) = '\\server_name\folder_name\folder_name_2\file_1.txt';
select right(@file_path, charindex(char(92), reverse(@file_path)) - 1)

 

Did this topic help you find an answer to your question?
This topic has been closed for comments

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings