Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Find Exact Directory Name Of Variable Directory Name

DZone's Guide to

Find Exact Directory Name Of Variable Directory Name

·
Free Resource
This sql server procedure help you, if you have remmember some string of your directory and path name then you will get the exact directory name of that path.


create proc usp_srchDir
(
	@pathName nvarchar(100),
	@strDirName nvarchar(50),
	@ExactName nvarchar(20) OUTPUT
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @strCMD nvarchar(500)
	SET @strCMD='dir  "'+ @pathName +'" /ad/o | find /I "'+@strDirName+'"'
	create table tblFindDIR(SearchDIRName nvarchar(200))
	insert into tblFindDIR(SearchDIRName)	
	exec master.dbo.xp_cmdshell @strCMD
	delete from tblFindDIR where isnull(SearchDIRName,'')=''
	select @ExactName=ltrim(rtrim(right(SearchDIRName,20))) from tblFindDIR where SearchDIRName like '%'+@strDirName+'%' 
	drop table tblFindDIR
	SET NOCOUNT OFF
END

GO

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}