Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
X-Factor
Constraint Violating Yak Guru
392 Posts |
Posted - 2005-06-20 : 19:09:26
|
| Hi,I have set up a database job which runs once a day and deletes database entities which have expired due to their age.Some of these entities have files associated with them - the entities reference the file name.How can I trigger the deletion of these files?Cheers,XF. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-06-20 : 19:37:40
|
| Where do the files exist? On the database server? Please provide more information about what an entity is.Tara |
 |
|
|
jhermiz
3564 Posts |
Posted - 2005-06-20 : 23:12:14
|
Hi XF,When you say entity, do you mean a record in the database. So a record may have a file associated with it?If you are storing the path of the file in your record than I think it is possible.Could you use xp_cmdshell?Try this...DECLARE @PathOfFile varchar(255)--snatch the pathSET @PathOfFile = ('del ' + (SELECT YourPath FROM YourTable WHERE ID = @SomeID))EXEC xp_cmdshell @PathOfFile Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]Imperfection living for perfection -- [url]http://jhermiz.blogspot.com/[/url] |
 |
|
|
X-Factor
Constraint Violating Yak Guru
392 Posts |
Posted - 2005-06-21 : 07:39:02
|
| Seems to work except the live server is saying "Could not find stored procedure 'xp_cmdshell'." |
 |
|
|
jhermiz
3564 Posts |
Posted - 2005-06-21 : 07:53:37
|
try this:EXEC master..xp_cmdshell @PathOfFile Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]Imperfection living for perfection -- [url]http://jhermiz.blogspot.com/[/url] |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-06-21 : 12:33:23
|
| Keep in mind the permissions that are required with xp_cmdshell. If this is to be run from your application, you need to be very, very careful with it.Tara |
 |
|
|
X-Factor
Constraint Violating Yak Guru
392 Posts |
Posted - 2005-06-21 : 13:03:49
|
| Its only to be called by the database job and the path to the files is hardcoded into the sp. |
 |
|
|
|
|
|