Author |
Topic |
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-02-28 : 11:51:46
|
Hi, how can I delete files and directories with T-SQLThank you |
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-02-28 : 12:30:27
|
This will remove directory:declare @rmdircmd nvarchar(280);set @rmdircmd = N'RMDIR C:\blah\blah\ /S /Q'exec master.dbo.xp_cmdshell @rmdircmd, no_output Hopefully it will get You started if you know the dos commands.rockmoose |
|
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-02-28 : 15:28:59
|
Thank you very much.It was very helpful |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-02-28 : 15:35:58
|
You're welcome.Post back if there is anything else...rockmoose |
|
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-03-01 : 14:32:30
|
I forgot, and about the files, is it still the rmdir command?Thanks |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-03-01 : 15:00:31
|
from the command prompt type "del /?" and You will see the syntax for the DEL command.DEL is used for deleting files.rockmoose |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2005-03-01 : 15:01:36
|
Well, that depends. Are the files in the directory? If they're in another directory, you will need to use the DEL command. Otherwise, the RMDIR will work. You'll have to use the /S option though.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
|
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-03-01 : 15:19:27
|
Ouch, this is fast replying. It must be the forum with the most active members!Thank you Derrick |
|
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-03-01 : 15:21:43
|
...and moose! |
|
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-03-01 : 15:28:17
|
Finally, here's what i did:declare @rmdircmd nvarchar(280);declare @rmdircmd1 nvarchar(280);set @rmdircmd = N'del \\cgcapp\Report\presence.dbf /s'set @rmdircmd = N'del \\cgcapp\Report\presence.rdf /s'exec master.dbo.xp_cmdshell @rmdircmd, no_output |
|
|
scrap
Yak Posting Veteran
57 Posts |
Posted - 2005-03-01 : 15:44:41
|
Actually, it looks more like:declare @rmdircmd nvarchar(280);declare @rmdircmd1 nvarchar(280);set @rmdircmd = N'del \\cgcapp\Report\presence.dbf /q'set @rmdircmd1 = N'del \\cgcapp\Report\presence.rdf /q'exec master.dbo.xp_cmdshell @rmdircmd, no_outputexec master.dbo.xp_cmdshell @rmdircmd1, no_outputThank you all!! |
|
|
SqlNewbieMe
Starting Member
2 Posts |
Posted - 2014-01-09 : 14:13:33
|
Hi, is there a way to remove directories older than x days using T-sqlThanks |
|
|
SqlNewbieMe
Starting Member
2 Posts |
Posted - 2014-01-09 : 14:15:46
|
Hi, is there a way to remove directories older than x days using T-sql. The above tsql works even on an UNC path only issue is to remove Directories older than x days..Thanks |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2014-01-09 : 15:26:41
|
use the FORFILES command.here is an example. |
|
|
|