Link to home
Start Free TrialLog in
Avatar of samalraj
samalrajFlag for India

asked on

how to delete physical files in a folder through sql server 2005 (procedure)

we will send folder path as a parameter, need to delete all the files in the specific folder
NOTE : not the folder

here is my code below. thanks in advance for spending your precious time in it.

EXEC @HR = SP_OACREATE 'SCRIPTING.FILESYSTEMOBJECT',@OLE_FILESYSTEM OUT
EXEC @HR = SP_OAMETHOD @OLE_FILESYSTEM, 'DELETEFILE',NULL, @FILE_PATH
EXEC @HR = SP_OADESTROY @OLE_FILESYSTEM

Line 2 returns -2147352570
thanks
amal
Avatar of theGhost_k8
theGhost_k8
Flag of India image

following command will delte x.txt from c:\
exec xp_cmdshell "del c:\x.txt";
ASKER CERTIFIED SOLUTION
Avatar of sameer2010
sameer2010
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Note that you will have to get xp_cmdshell enabled through services configuration.
Avatar of samalraj

ASKER

Thank you very much