Extract file name from a file path


Userlevel 4

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)

 


0 replies

Be the first to reply!

Reply