开发者

SSIS File exist check without script task

Is there any way to check if 开发者_Go百科file exist without script task? May be foreach loop container or something else..


I figured out how to check for Files without using a Script Task.

1) Add a ForEach Loop Container to your Control Flow.
2) On ForEach Collection pane, set Enumerator to "Foreach File Enumerator"
3) Set Folder to your Source Folder.
4) Set Files to your File Spec (*.*).
5) On Variable Mappings, create new variable "User::FileExistsFileName"
6) You then just need to configure two output Lines for the ForEach Loop:

7) For Success Line:  Double-click the Connector Line, set:

Evaluation operation:  Expression
Value:  Success
Expression:  @[User::FileExistsFileName] != ""

8) For Failure Line, set:

Evaluation operation:  Expression or Constraint
Value:  Failure
Expression:  @[User::FileExistsFileName] == ""

I like to set the Evaluation operation for Failure to "Expression or Constraint" simply to turn the line Red.


If you're OK with using a custom component, try this one: File Properties Task. It's open source, so you can see exactly what it's doing. You need to install it on your dev and prod boxes - with the installer or manually into the GAC. But do that, and you have a drag and drop task easier to use than the File System Task... but then, I'm biased...


I was just looking for the same thing and thought I would share the solution I finally came up with, just in case anyone is still interessted:

I just used an execute process task to run a simple "IF NOT EXIST" command, handling the exit codes in the package.

Relevant task configuration:

Executable: C:\Windows\System32\cmd.exe
FailTaskIfReturnCodeIsNotSuccessValue: True
Expressions > Arguments: "/C IF NOT EXIST \"" + @[User::PATH_TO_FILE] + "\" ( EXIT 1 ) else ( EXIT 0 )"
WindowStyle: Hidden
MaximumErrorCount: a number equally or higher than the number it is potentially failing (e.g. when checking files existence in a loop)

Add an OnError EventHandler to the Execute Process Task and set system variable Propagate to False to stop it bubbling up the failure(s) to the parent container. If you don't want to bother about the MaximumErrorCount and failing tasks you could simply "ECHO" the result and pass the StdOut to a variable you can then check inside an expression.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜