FolderDelete
Deletes a Folder and its content
- Stored Procedure
- SQL Server Compatibility: 2008, 2012, 2014, 2016, 2017
EXEC SQLHTTP.net.FolderDelete @FolderPath
Name | Type | Description |
---|---|---|
@FolderPath | varchar(MAX) | Full path to a folder |
@Recursive | bit | 1 = All directories, subdirectories, and files in FolderPath will be deleted first 0 = Existing directories, subdirectories, and files in FolderPath will NOT be deleted. If any exist, an error will be raised. |
Accessing the file system will be performed in the context of the SQL Server instance process. You can set SQL Server to run using a specific network account, or a Local System Account.
Recursive delete of a folder:
1 2 3 4 5 6 7 8 9 10 11 |
DECLARE @FolderPath varchar(MAX) DECLARE @Recursive bit --Assign a path to a folder that the executing user has delete permissions on SET @FolderPath = 'C:\ThisFolderExists' SET @Recursive = 1 --all folders, subfolders and files inside FolderPath will be deleted first EXEC SQLHTTP.net.FolderDelete @FolderPath, @Recursive |
1 2 3 |
Command(s) completed successfully. |
Non-Recursive delete of a non-empty folder:
1 2 3 4 5 6 7 8 9 10 11 |
DECLARE @FolderPath varchar(MAX) DECLARE @Recursive bit --Assign a path to a folder that the executing user has delete permissions on SET @FolderPath = 'C:\ThisFolderExists' SET @Recursive = 0 --no folders, subfolders, or files inside FolderPath will be deleted EXEC SQLHTTP.net.FolderDelete @FolderPath, @Recursive |
1 2 3 4 |
Msg 50000, Level 16, State 1, Procedure DeleteFolder, Line 12 [Batch Start Line 0] The directory is not empty. |
- CodePageEncodings
- FileCopy
- FileDecrypt
- FileDelete
- FileEncrypt
- FileMove
- FileRead
- Files_To_Table
- FileWrite
- FolderCopy
- FolderCreate
- FolderDelete
- FolderMove
- Folders_To_Table
- GlobalTable_To_File
- IsExistingFile
- IsExistingFolder
- TempPath
- ZipEntryAppend
- ZipEntryRemove
- ZipExtract_To_Folder
- ZipExtract_To_Table