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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL Server delete files

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
Go to Top of Page

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 path
SET @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]
Go to Top of Page

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'."
Go to Top of Page

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]
Go to Top of Page

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
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -