June 30, 2008 at 11:08 pm
Hi there,
I need to delete an entire Folder that gets created programmatically on a daily basis. I'm fairly new to SQL so don't know how to get around this. We already use xp_cmdshell extended procedures to clean up various other old files and was wondering if it is possible to delete an entire folder (which isn't empty) using an xp_cmdshell extended procedure. If so what would be the command to achieve this?
Thanks
J
PS We are running SQL 2000.
July 1, 2008 at 11:45 am
Actually, it doesn't matter what version of SQL Server you are using. xp_CmdShell issues command shell scripts to Windows. Like the old DOS commands (if you're old enough to remember those).
Go to the start menue, click on Run, type in "cmd" and hit enter. It will open a command shell window. Type "help" and hit enter. It will give you a list of the valid commands. "RMDIR" is the one for deleting a directory. It will remove all files and sub-directories. For the exact syntax, type "RMDIR /?" and hit enter (again, in the command window). It will give you the switches and options for that command.
Once you've worked out what command you want to issue, make that the command you give to xp_CmdShell, and it will do it.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
July 2, 2008 at 7:54 am
If you need to do this on a regular basis, and you have Standard or Enterprise edition (I don't remember if the workgroup edition of SQL Server has SQL Server Agent, but I believe it does), you can create a SQL Server Agent Job that performs these tasks (in an Operating System (CmdExec) task), and then lock down who has access to run the job.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply