Situatie
In cazul in care avem nevoie ca, in timpul executiei unei proceduri stocate pe serverul de sql, sa cream un folder de windows, am facut o procedura ce primeste ca parametru o cale de folder de windows, iar procedura va crea in acea cale folderul dorit. Spre exemplu:
- procedura primeste ca parametru C:\Windows\Test\ si ea va crea folderul Test in calea existenta C:Windows.
- procedura primeste ca parametru C:\Test1\Test2\ si ea va crea in partiatia existanta C: folderul Test1 in care va crea subfolderul Test2.
Solutie
— exec BD_CreateWinFolder_prc ‘c:\test1\test2’
alter procedure BD_CreateWinFolder_prc
@cale_nume_folder varchar(max)
as
SET NOCOUNT ON
DECLARE @DataPath nvarchar(500)
DECLARE @DirTree TABLE (subdirectory nvarchar(255), depth INT)
SET @DataPath = @cale_nume_folder
INSERT INTO @DirTree(subdirectory, depth)
EXEC master.sys.xp_dirtree @DataPath
IF NOT EXISTS (SELECT 1 FROM @DirTree)
EXEC master.dbo.xp_create_subdir @DataPath
DELETE FROM @DirTree
SET NOCOUNT OFF
Leave A Comment?