Reputation: 73
I want to check if sub-folder exists or not. If exists, move on. If not exists go to next task.
My sub-folder is "C:\Folder1\Folder2\Folder3" I want to check if Folder3 is exists or not.
I worked on it. Create 2 variables
1> FolderPath = C:\Folder1\Folder2
2> FolderExists = Boolean = False
Script Task ReadOnlyVariable = @FolderPAth ReadWriteVariable = @FolderExists
Following script I add in edit script
Dim DirExists As String
DirExists = Dir(CStr(Dts.Variables("Folder3").Value))
If DirExists <> "" Then
Dts.Variables("Folder3").Value = True
Else
Dts.Variables("Folder3").Value = False
End If
Can some one correct me please.
Upvotes: 4
Views: 6788
Reputation: 14341
Based on your comment it doesn't seem like you will care if it is c# of VB so here are steps from beginning to end on how to test Existence of a folder and use it in constrained precedence.
using System.IO;
Scroll to the definition of the Main() sub and add the first line after "TODO" below so that the routine becomes:
public void Main()
{
// TODO: Add your code here
Dts.Variables["User::FolderExists"].Value = Directory.Exists(Dts.Variables["User::FolderPath"].Value.ToString());
Dts.TaskResult = (int)ScriptResults.Success;
}
The script task is complete and you should now be able to use the FolderExists variable as the expression for constrained precedence.
this solution was fully tested and is operational
Upvotes: 3