发布时间:2019-03-21编辑:佚名阅读(2185)
1、根据路径获取文件名
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | -- ============================================= -- Author: Paul Griffin -- Create date: 18 January 2015 -- Description: Returns a filename with extension -- from a full path: -- D:\Temp\Resources\Images\My.Picture.jpg -- ==> My.Picture.jpg -- ============================================= CREATE FUNCTION [dbo].[GetFileName] ( @Path NVARCHAR( MAX ) ) RETURNS NVARCHAR( MAX ) AS BEGIN DECLARE @FileName NVARCHAR( MAX ) DECLARE @ReversedPath NVARCHAR( MAX ) SET @ReversedPath = REVERSE(@Path) SELECT @FileName = RIGHT (@Path, CHARINDEX('\', @ReversedPath)-1) RETURN @FileName END |
2、根据路径获取文件名(去掉扩展名)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | -- ============================================= -- Author: Paul Griffin -- Create date: 18 January 2015 -- Description: Returns a filename without extension -- from a full path: -- D:\Temp\Resources\Images\My.Picture.jpg -- ==> My.Picture -- ============================================= CREATE FUNCTION [dbo].[GetFileNameWithoutExtension] ( @Path NVARCHAR( MAX ) ) RETURNS NVARCHAR( MAX ) AS BEGIN DECLARE @FileName NVARCHAR( MAX ) DECLARE @ReversedPath NVARCHAR( MAX ) DECLARE @ExtLength INT SET @ReversedPath = REVERSE(@Path) SELECT @ExtLength = CHARINDEX( '.' , @ReversedPath) SELECT @FileName = RIGHT (@Path, CHARINDEX('\', @ReversedPath)-1) SELECT @FileName = LEFT (@FileName, LEN(@FileName) - @ExtLength) RETURN @FileName END |
3、根据路径获取路径目录(无文件名)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | -- ============================================= -- Author: Paul Griffin -- Create date: 18 January 2015 -- Description: Returns the path without the file name -- from a full path: -- D:\Temp\Resources\Images\My.Picture.jpg -- ==> D:\Temp\Resources\Images -- ============================================= CREATE FUNCTION [dbo].[GetDirectoryPath] ( @Path NVARCHAR( MAX ) ) RETURNS NVARCHAR( MAX ) AS BEGIN DECLARE @FileName NVARCHAR( MAX ) DECLARE @ReversedPath NVARCHAR( MAX ) DECLARE @PathLength INT SET @ReversedPath = REVERSE(@Path) SELECT @PathLength = CHARINDEX('\', @ReversedPath) SELECT @FileName = LEFT (@Path, LEN(@Path) - @PathLength) RETURN @FileName END |
4、获取文件扩展名
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | -- ============================================= -- Author: Paul Griffin -- Create date: 18 January 2015 -- Description: Returns the extension only -- from a full path: -- D:\Temp\Resources\Images\My.Picture.jpg -- ==> jpg -- ============================================= CREATE FUNCTION [dbo].[GetExtension] ( @Path NVARCHAR( MAX ) ) RETURNS NVARCHAR( MAX ) AS BEGIN DECLARE @FileName NVARCHAR( MAX ) DECLARE @ReversedPath NVARCHAR( MAX ) DECLARE @ExtLength INT SET @ReversedPath = REVERSE(@Path) SET @FileName = '' SELECT @ExtLength = CHARINDEX( '.' , @ReversedPath) IF (@ExtLength > 0) BEGIN SELECT @FileName = RIGHT (@Path, @ExtLength - 1) END RETURN @FileName END |
关键字: SQL Server 提取文件名
上一篇:ConfuserEx脱壳
下一篇:C#获取所有进程
0人
0人
0人
0人