Solved

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

Posted on 2013-10-30
2
908 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hyperlink data type in SQL 3 28
[SQL server / powershell] bulk delete table from CSV 8 33
sql server tables from access 18 22
SQL - Copy data from one database to another 6 19
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

810 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