Solved

SSIS 2008R2 VB.NET Script:  How to get the file name from a full path

Posted on 2013-10-30
2
913 Views
Last Modified: 2016-02-11
Hi All

I have a ForEach File Loop where I'm assigning the full path of a file to variable @sSourceFile.  Good to go.

Question:  Using either VB.NET script or a Derived Column expression, how do you get the file name?

Example:  @SourceFile = "H:\go\here\then\go\there\foo.txt"
Desired value:  foo.txt
0
Comment
Question by:Jim Horn
2 Comments
 
LVL 34

Assisted Solution

by:Brian Crowe
Brian Crowe earned 250 total points
ID: 39612672
SELECT SUBSTRING(@SourceFile, LEN(@SourceFile) - CHARINDEX('\', REVERSE(@SourceFile)) + 2, LEN(@SourceFile))
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 0 total points
ID: 39612697
Figured it out.

Up top in the declarations section...
Imports System.IO

Open in new window

... then in the main ...
Dim fi As System.IO.FileInfo = New FileInfo(Dts.Variables("sSourceFile").Value.ToString)
MsgBox("File name " + fi.Name)

Open in new window


Lowered points and awarded for the T-SQL answer, which may have been used if I couldn't come up with a VB.NET answer.

Thanks.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

My client has a dictionary table. They're defining a list of standard naming convention. Now, they are requiring my team to provide us a mechanism how to match new incoming data with existing data in their system.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question