INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Script Task for file exist not working

Script Task for file exist not working

(OP)
Hi All,
I have script task designed to look if a .xls file exists or not. It works correctly when the file is in network folder, but when it doesn't the False path doesn't fire. It still thinks it should look for the file and produces a check object exists error.

Package uses two variables;

@BolFileExists, Package, Boolean, False
@strFileLocation, Package, String, D:\xxxx\yyyy\aa.xls

Script Task: Readonly User::strFileLocation, Read Write User::BolFileExists

CODE -->

Imports System.IO



Public Class ScriptMain


    Public Sub Main()

        Dts.Variables("BolFileExists").Value = File.Exists(Dts.Variables("strFileLocation").Value.ToString())

        Dts.TaskResult = Dts.Results.Success



    End Sub



End Class 



RE: Script Task for file exist not working

I would use a breakpoint to look at the variables at the point after this script runs (use the breakpoint within SSIS not in the script). What is the var saying - true or false?

----------------------------------------
www.fountain.me.uk

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Bernard Baruch

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------

RE: Script Task for file exist not working

I'm suprised you don't get an error in the script task (in fact you probably are but it is getting masked by the Dts.TaskResult = Dts.Results.Success line

you are attempting to set a boolean variable equal to a string

try this instead

CODE

Dts.TaskResult = Dts.Results.Success
Try

Dts.Variables("BolFileExists").Value = File.Exists(Dts.Variables("strFileLocation").Value)

Catch ex as exception
'comment this out in production but use for testing
'should probably have some error handling here in case something goes wrong (access to LAN etc)
msgbox (ex.message.tostring)
Dts.TaskResult = Dts.Results.failure

end try 

I cannot emphasise enough the importance of error handing and the usage of TRY/CATCH constructs when writing code for ETL processes

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244: How to get the best answers before you ask a question

RE: Script Task for file exist not working

Good spot Geoff - didnt notice that!

Very wise words about the error handling. I would go as far as to say all scripts should have a Dts.Results.failure
somewhere!

----------------------------------------
www.fountain.me.uk

Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind - Bernard Baruch

Computer Science is no more about computers than astronomy is about telescopes - EW Dijkstra
----------------------------------------

RE: Script Task for file exist not working

agreed - should always be able to handlefailures gracefully even if youexpect no failure can occur

In this instance you could hae a communication link failure to the LAN which would cause an error with the file.exists and therefore should be able to be trappd and reported

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244: How to get the best answers before you ask a question

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close