Extract file name from a file path

  • 17 June 2020
  • 0 replies
  • 84 views

Userlevel 5

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)

 


This topic has been closed for comments