I need to delete file with folder using sql
so i am using xp_cmdshell.
My Folder structure is
Folder-1
|
|
Folder 2 ----------------------------------------------Folder -3
| |
files.csv files.csv
I need to delete Folder-1, so that it will delete Folder 2 and folder 3 and the files containing it.
I tried using set @cmd= ‘RMDIR “C:\Folder-1’
exec master..xp_cmdshell @cmd
RMDIR needs the folder to be empty. so we need to first delete the file using del command.
Then using RMDIR to delete folder 2 and folder 3, then using RMDIR to delete folder-1
Is there anyway to delete the folder with file using single command by xp_cmdshell
Try RMDIR /S /Q C:\Folder-1
The /S Removes all files and directories in the specified directory/folder. the /Q is quiet mode and will not ask if its ok to delete.
HTH