December 27, 2010 at 10:20 pm
Hi,
I am using the script task to delete the old files(older than 10 days) present in a particular folder. (D:\FIles)
Code to delete the old files:
Dim oFSO
Dim sDirectoryPath
Dim oFolder
Dim oFileCollection
Dim oFile
Dim iDaysOld
'Archive Files
iDaysOld = CInt(Dts.Variables("User::DaysKeepArchive").Value)
'Alter the variable DaysKeepArchive as needed.
oFSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = CStr(Dts.Variables("User::ArchiveFiles").Value)
'Alter the variable ArchiveFiles as needed.
oFolder = oFSO.GetFolder(sDirectoryPath)
oFileCollection = oFolder.Files
'Walk through each file in this folder collection.
'If it is older than DaysKeepArchive days, then delete it.
For Each oFile In oFileCollection
If oFile.DateLastModified < (DateTime.Now.AddDays(-iDaysOld)) Then
oFile.Delete(True)
End If
Next
'Clean up
oFSO = Nothing
oFolder = Nothing
oFileCollection = Nothing
oFile = Nothing
Dts.TaskResult = Dts.Results.Success
But i am getting the following error when execute it :
Exception from HRESULT: 0x800A0046 (CTL_E_PERMISSIONDENIED)
at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
at ScriptTask_c546ddcc3bdc4c85a39194f9edce9ca6.ScriptMain.Main() in dts://Scripts/ScriptTask_c546ddcc3bdc4c85a39194f9edce9ca6/ScriptMain:line 41
Can somebody help on this.
THANKS in Advance.
December 28, 2010 at 4:09 am
maybe this is shorter and fills in you needs: the maintenance cleanup task
you can even script it http://sqlblog.com/blogs/andy_leonard/archive/2009/03/11/xp-delete-file.aspx
December 28, 2010 at 8:10 am
It seems to be a permission issue. Are you sure permissions on the folder are set up correctly?
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
October 11, 2012 at 6:02 am
Has any1 ever used a long path tool like the one in pathtoodeep.com?
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy