in SQL 2000 delete photos in the file system files

Hello there,
I am trying to delete unused photos in the server file system according to a table's key. I have test to delete single file with the following T-Sql script and it worked, but when I create a cursor to run the batch, it did not delete anything.
Is there a better approach for this kind of task?
Please help. Thanks .
declare abc cursor for
select [key]
from tempPhotoZ
order by [key]
open abc
declare @skey varchar(15)
declare @str varchar(200)
set @str='DEL e:\Dailypull\photographs\'
Fetch Next from abc into @skey
While @@Fetch_status =0
set @str=@str+@skey+'*.jpg'
Execute master.dbo.xp_cmdshell @str
Fetch next from abc into @skey
close abc
deallocate abc

Open in new window

Who is Participating?
dodge20Connect With a Mentor Commented:
Yes you still need the del.

I would put a select @str after your set statement to see what the actual command is getting passed to xp-cmdshell.

Also I assume  xp-cmdshell is enabled?
What version of windows? In 2003 there is a forfiles command that works great.
tomcattyyAuthor Commented:
It's windows 2003 and I am checking the link. thanks
tomcattyyAuthor Commented:
Hello dodge20,

use forfiles do I still need the cmd del ? Can you point out what is wrong with my script above?
tomcattyyAuthor Commented:
Yes the xp_cmdshell is enabled.
I found the @str first time is correct and the next run only makes the @str longer by adding the new photo number.
first run
DEL e:\Dailypull\photographs\90022782129*.jpg
DEL e:\Dailypull\photographs\90022782129*.jpg9025655912*.jpg
I change the code and this time the select @str shows it is correct line by line
Thanks for your help

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.