SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 delete dir with t-SQL
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

scrap
Yak Posting Veteran

57 Posts

Posted - 02/28/2005 :  11:51:46  Show Profile  Reply with Quote
Hi, how can I delete files and directories with T-SQL

Thank you

rockmoose
SQL Natt Alfen

Sweden
3279 Posts

Posted - 02/28/2005 :  12:30:27  Show Profile  Reply with Quote
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
Go to Top of Page

scrap
Yak Posting Veteran

57 Posts

Posted - 02/28/2005 :  15:28:59  Show Profile  Reply with Quote
Thank you very much.
It was very helpful
Go to Top of Page

rockmoose
SQL Natt Alfen

Sweden
3279 Posts

Posted - 02/28/2005 :  15:35:58  Show Profile  Reply with Quote
You're welcome.
Post back if there is anything else...

rockmoose
Go to Top of Page

scrap
Yak Posting Veteran

57 Posts

Posted - 03/01/2005 :  14:32:30  Show Profile  Reply with Quote
I forgot, and about the files, is it still the rmdir command?
Thanks
Go to Top of Page

rockmoose
SQL Natt Alfen

Sweden
3279 Posts

Posted - 03/01/2005 :  15:00:31  Show Profile  Reply with Quote
from the command prompt type "del /?" and You will see the syntax for the DEL command.
DEL is used for deleting files.

rockmoose
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

USA
4184 Posts

Posted - 03/01/2005 :  15:01:36  Show Profile  Visit derrickleggett's Homepage  Send derrickleggett an AOL message  Send derrickleggett a Yahoo! Message  Reply with Quote
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.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

scrap
Yak Posting Veteran

57 Posts

Posted - 03/01/2005 :  15:19:27  Show Profile  Reply with Quote
Ouch, this is fast replying. It must be the forum with the most active members!

Thank you Derrick
Go to Top of Page

scrap
Yak Posting Veteran

57 Posts

Posted - 03/01/2005 :  15:21:43  Show Profile  Reply with Quote
...and moose!
Go to Top of Page

scrap
Yak Posting Veteran

57 Posts

Posted - 03/01/2005 :  15:28:17  Show Profile  Reply with Quote
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
Go to Top of Page

scrap
Yak Posting Veteran

57 Posts

Posted - 03/01/2005 :  15:44:41  Show Profile  Reply with Quote
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_output
exec master.dbo.xp_cmdshell @rmdircmd1, no_output

Thank you all!!
Go to Top of Page

SqlNewbieMe
Starting Member

India
2 Posts

Posted - 01/09/2014 :  14:13:33  Show Profile  Reply with Quote
Hi, is there a way to remove directories older than x days using T-sql

Thanks
Go to Top of Page

SqlNewbieMe
Starting Member

India
2 Posts

Posted - 01/09/2014 :  14:15:46  Show Profile  Reply with Quote
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
Go to Top of Page

russell
Pyro-ma-ni-yak

USA
5072 Posts

Posted - 01/09/2014 :  15:26:41  Show Profile  Visit russell's Homepage  Reply with Quote
use the FORFILES command.

here is an example.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000