samalraj
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.FILESYSTEMOBJEC T',@OLE_FI LESYSTEM OUT
EXEC @HR = SP_OAMETHOD @OLE_FILESYSTEM, 'DELETEFILE',NULL, @FILE_PATH
EXEC @HR = SP_OADESTROY @OLE_FILESYSTEM
Line 2 returns -2147352570
thanks
amal
NOTE : not the folder
here is my code below. thanks in advance for spending your precious time in it.
EXEC @HR = SP_OACREATE 'SCRIPTING.FILESYSTEMOBJEC
EXEC @HR = SP_OAMETHOD @OLE_FILESYSTEM, 'DELETEFILE',NULL, @FILE_PATH
EXEC @HR = SP_OADESTROY @OLE_FILESYSTEM
Line 2 returns -2147352570
thanks
amal
http://www.kodyaz.com/articles/delete-file-from-sql-server-xp-cmdshell-ole-automation-procedures.aspx
following command will delte x.txt from c:\
exec xp_cmdshell "del c:\x.txt";
exec xp_cmdshell "del c:\x.txt";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Note that you will have to get xp_cmdshell enabled through services configuration.
ASKER
Thank you very much