Search
 
SCRIPT & CODE EXAMPLE
 

SQL

create directory in sql server

/*    
DECLARE @outPutPath2 NVARCHAR(500)    
EXEC sp_un_CreateDirectory 'folder1folder2folder3folder4', 'TEST01', @outPutPath2 OUTPUT       
EXEC sp_un_CreateDirectory @outPutPath2, 'TEST01', @outPutPath2 OUTPUT    
*/    
    
CREATE PROCEDURE sp_un_CreateDirectory(    
 @parentDirectory NVARCHAR(500)    
 ,@folderName NVARCHAR(200)    
 ,@outPutPath NVARCHAR(500) = NULL  OUTPUT    
)    
    
AS     
    
/*Enable the functionality of file processing      
    
EXEC master.dbo.sp_configure 'show advanced options', 1      
RECONFIGURE      
      
EXEC master.dbo.sp_configure 'xp_cmdshell', 1      
RECONFIGURE      
    
exec xp_cmdshell 'net use SICEMsharedData password /USER:julyservices
asel'    
      
*/     
    
DROP TABLE IF EXISTS #TempTableParentDir    
DROP TABLE IF EXISTS #TempTableDestinationDir    
    
DECLARE @SQLcmd NVARCHAR(500), @IsDesDirectory BIT, @DesParentDirectoryExists BIT;      
CREATE TABLE #TempTableParentDir (FilesExists BIT, IsDirectory BIT, ParentDirectoryExists BIT);      
CREATE TABLE #TempTableDestinationDir (FilesExists BIT, IsDirectory BIT, ParentDirectoryExists BIT);      
    
INSERT INTO #TempTableParentDir      
EXEC Master.dbo.xp_fileexist @parentDirectory     
    
SELECT @IsDesDirectory = IsDirectory ,@DesParentDirectoryExists = ParentDirectoryExists FROM #TempTableParentDir      
    
IF(@DesParentDirectoryExists = 0) RETURN;   
  
IF(@IsDesDirectory = 0 AND @DesParentDirectoryExists = 1)      
BEGIN  
 SET @SQLcmd = 'mkdir'+@parentDirectory;      
 EXEC MASTER..xp_cmdshell @SQLcmd      
END     
    
DECLARE @Inpath  VARCHAR(200)='';      
SET @Inpath = @parentDirectory+''+@folderName;      
  
print(2);    
INSERT INTO #TempTableDestinationDir      
EXEC Master.dbo.xp_fileexist @Inpath     
    
SELECT @IsDesDirectory = IsDirectory ,@DesParentDirectoryExists = ParentDirectoryExists FROM #TempTableDestinationDir      
IF(@DesParentDirectoryExists = 0) RETURN;    
IF(@IsDesDirectory = 0 AND @DesParentDirectoryExists = 1)      
BEGIN      
 SET @SQLcmd = 'mkdir'+@Inpath;      
 EXEC MASTER..xp_cmdshell @SQLcmd      
END     
    
DROP TABLE IF EXISTS #TempTableParentDir    
DROP TABLE IF EXISTS #TempTableDestinationDir    
    
SELECT @outPutPath =@Inpath    
    
RETURN    
Comment

PREVIOUS NEXT
Code Example
Sql :: tablo silme SQL 
Sql :: how to login to mysql as normal user in ubuntu 
Sql :: select query in mongodb 
Sql :: convert all tables in database to from myisam to innodb 
Sql :: Inser Dataframe into mysql 
Sql :: sql alias 
Sql :: dump db only triggers mysql 
Sql :: how to dump .csv file into mysql 
Sql :: automatically update database last seen datetime in sql 
Sql :: longtext sql 
Sql :: mysql group rows with same value 
Sql :: identify rows with 2 same column value and delete duplicate mysql 
Sql :: MySQL OR 
Sql :: sql alter table 
Sql :: psql: error: FATAL: database "odoo" does not exist 
Sql :: timestamp to date sql server 
Sql :: mysql undo delete 
Sql :: sql to excel pgadmin 
Sql :: google sheets filter rows above current cell 
Sql :: oracle tablespace autoextend 
Sql :: psql query execution time 
Sql :: where name ends in SQL 
Sql :: drop constraint in ms sql 
Sql :: mysql --version 
Sql :: how to compare two columns in sql server 
Sql :: select * from 
Sql :: table user postgres 
Sql :: how to join result table in mysql 
Sql :: 18446744073709551615 mariadb left join order by 
Sql :: sql examples from framework 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =