We can create Folder in local Hard Disk directly from SQL. Check below script for Create Folder. Below query first check for the existence of folder in HDD if not found than it creates new.
DECLARE @ChkFolder AS nvarchar(4000)
DECLARE @Folder_Exists AS INT
set @ChkFolder = 'C:\Temp\'
DECLARE @File_Result TABLE
(File_Exists INT,
File_Is_A_Folder INT,
Parent_Folder_Exists INT
)
INSERT INTO @File_Result
(File_Exists, File_Is_A_Folder, Parent_Folder_Exists)
EXEC [master].dbo.xp_FileExist @ChkFolder
SELECT @Folder_Exists = File_Is_A_Folder
FROM @File_Result
--script to create Folder
if @Folder_Exists = 0
BEGIN
PRINT 'Folder is not exists, creating new one '
EXECUTE [master].dbo.xp_Create_SubDir @ChkFolder
PRINT @ChkFolder + 'created on ' + @@servername
END
ELSE
PRINT 'Folder already exists'
GO
DECLARE @ChkFolder AS nvarchar(4000)
DECLARE @Folder_Exists AS INT
set @ChkFolder = 'C:\Temp\'
DECLARE @File_Result TABLE
(File_Exists INT,
File_Is_A_Folder INT,
Parent_Folder_Exists INT
)
INSERT INTO @File_Result
(File_Exists, File_Is_A_Folder, Parent_Folder_Exists)
EXEC [master].dbo.xp_FileExist @ChkFolder
SELECT @Folder_Exists = File_Is_A_Folder
FROM @File_Result
--script to create Folder
if @Folder_Exists = 0
BEGIN
PRINT 'Folder is not exists, creating new one '
EXECUTE [master].dbo.xp_Create_SubDir @ChkFolder
PRINT @ChkFolder + 'created on ' + @@servername
END
ELSE
PRINT 'Folder already exists'
GO
No comments:
Post a Comment