sql - SSIS - Script Task Check if Subfolder Exists -


i want check if sub-folder exists or not. if exists, move on. if not exists go next task.

my sub-folder "c:\folder1\folder2\folder3" want check if folder3 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 add in edit script

    dim direxists string      direxists = dir(cstr(dts.variables("folder3").value))      if direxists <> ""          dts.variables("folder3").value = true      else          dts.variables("folder3").value = false      end if 

can 1 correct me please.

based on comment doesn't seem care if c# of vb here steps beginning end on how test existence of folder , use in constrained precedence.

  • define 2 package level variables: folderpath string, folderexists boolean enter image description here
  • add script task , configure c# , add folderpath readonlyvariable , folderexists readwritevariable enter image description here
  • click edit edit script
  • scroll "#region namespaces" near top , add using system.io; enter image description here
  • scroll definition of main() sub , add first line after "todo" below routine becomes:

    public void main() {     // todo: add code here     dts.variables["user::folderexists"].value = directory.exists(dts.variables["user::folderpath"].value.tostring());      dts.taskresult = (int)scriptresults.success; } 
  • the script task complete , should able use folderexists variable expression constrained precedence.

  • add next step in package , connect green success arrow double click arrow , set constraint options evaluate expression , constraint , expression folderexists variable. enter image description here

this solution tested , operational


Comments