tomcattyy
asked on
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 .
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
Begin
set @str=@str+@skey+'*.jpg'
Execute master.dbo.xp_cmdshell @str
Fetch next from abc into @skey
End
close abc
deallocate abc
ASKER
It's windows 2003 and I am checking the link. thanks
ASKER
Hello dodge20,
use forfiles do I still need the cmd del ? Can you point out what is wrong with my script above?
Thanks
use forfiles do I still need the cmd del ? Can you point out what is wrong with my script above?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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\9 0022782129 *.jpg
then
DEL e:\Dailypull\photographs\9 0022782129 *.jpg90256 55912*.jpg
....continue.
I change the code and this time the select @str shows it is correct line by line
Thanks for your help
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\9
then
DEL e:\Dailypull\photographs\9
....continue.
I change the code and this time the select @str shows it is correct line by line
Thanks for your help
http://technet.microsoft.com/en-us/library/cc753551(WS.10).aspx