SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


"Delete files older than X days" error


"Delete files older than X days" error

Author
Message
marees.inspire
marees.inspire
SSC Journeyman
SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)SSC Journeyman (96 reputation)

Group: General Forum Members
Points: 96 Visits: 247
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:BigGrinaysKeepArchive").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.
Marco V
Marco V
Mr or Mrs. 500
Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)Mr or Mrs. 500 (552 reputation)

Group: General Forum Members
Points: 552 Visits: 569
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
Koen Verbeeck
Koen Verbeeck
One Orange Chip
One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)One Orange Chip (27K reputation)

Group: General Forum Members
Points: 27587 Visits: 13268
It seems to be a permission issue. Are you sure permissions on the folder are set up correctly?


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
gabrielko_47
gabrielko_47
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 52
Has any1 ever used a long path tool like the one in pathtoodeep.com?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search