September 9, 2009 at 8:56 am
Hi,
I have a for each loop container that results a variable 'USER::Path' which holds a server path (\\serverA\folder1\folder2). So for each iteration the value of the 'USER::Path' changes, meaning for each iteration, variable gets a new server path .
My question is how do I delete text files in those folders.
thank you...
September 9, 2009 at 9:59 am
I have vb script to do the above task but I get the following errors
Public Sub Main()
Dim Path As String
Dim FSO
Path = CStr(Dts.Variables("User::Path").Value)
FSO = CreateObject("Scripting.FileSystemObject")
FSO.DeleteFile(Path & "Denials_*.txt")
FSO = Nothing
Dts.TaskResult = Dts.Results.Success
End Sub
Error:Option Strict On requires all variable declarations to have an 'As' clause. Line Text: Dim FSO
Error : Option Strict On disallows late binding. FSO.DeleteFile(Path & "Denials_*.txt")
Any help will be appreciated
September 9, 2009 at 10:11 am
FSO needs a datatype in the Dim statement ...
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
September 9, 2009 at 10:13 am
what should be the datatype...
September 9, 2009 at 10:13 am
If you want to delete every text file in the folder you can:
Insert another foreach loop container inside of the one you have now
Set your "Enumerator" = Foreach File Enumerator
Open the expressions editor and set the "directory" property to your variable being filled by the previous loop.
Set the "Files" Textbox in the Enumeration Configuration to "*.txt"
add a variable with a name like "varFileToDel"
Set the variable mapping in the new "Foreach Loop Container" to varFileToDel
Add a File System Task to the Foreach Loop Container
Set Operation to Delete File
Set "Is source path variable" = True
Set "Source Variable" = varFileToDel
September 9, 2009 at 10:24 am
Actually, make sure you've got an
Imports System.IO
and then you should be able to
File.Delete(filespec)
without the need for the FSO.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
September 9, 2009 at 10:34 am
Thanks,I followed the steps in your reply, but I get following error
Validation error. File System Task File System Task: Variable "VarFileDel" is used as a source or destination and is empty.
any idea..
September 9, 2009 at 10:44 am
right click on the filesystems task and set the property "delay validation" = true
September 9, 2009 at 11:00 am
Hey Thanks for that, Now I do not see any errors, but when I execute the package the files wont get deleted.
I left the folder field in the enumerator configuration of For Each loop container empy.
i get following warning..
Validation warning. Foreach Loop Container : The path is empty.
coluld this be the reason for not deleting the files. If yes please let me know what should be there in that field.
I put a brkpoint on for each loop container to check to see if vardelfile variable is receiving any variable, it is not receiving any value in any iteration.
Please let me know if there anything I can do to make it work..
Thanks....
September 9, 2009 at 11:21 am
Everything that I gave you is based off of your first foreach loop,
put in a breakpoint and see if the mapped variable in the first loop is being filled
September 9, 2009 at 11:26 am
I left the folder field in the enumerator configuration of For Each loop container empy.
It is okay for this to be empty, by setting the directory property with the variable from your first foreach loop container, you are filling this value.
September 9, 2009 at 11:27 am
yes, all the variables are being populated except vardelfile.
September 9, 2009 at 11:28 am
I left the folder field in the enumerator configuration of For Each loop container empy.
It is okay for this to be empty, by setting the directory property with the variable from your first foreach loop container, you are filling this value.
September 9, 2009 at 11:43 am
My understanding is that your user variable "Path" is being filled with a value like: "\\serverA\folder1\folder2"
and your user variable "Path" is the variable being used in the second foreach loop as an expression for the property "Directory".
The second for each loop is being mapped to varFileDel and should be seeing values
like "\\serverA\folder1\folder2\SomeFile.txt"
This is all correct right?
September 9, 2009 at 11:57 am
yes thats correct
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply