Knowledge Base Article

Retrieve File Name during Import

'---------------------------------------------------------------------------------------
'Reference Code:  XFR_GetFilenameForSourceID 
'
'Description:     Gets the file name being processed, strips off the unique indentifier that XF
'                 adds to the file name, and returns the origninal source file name.
'
'Usage:           Typically used to derive the SourceID field in a data source.
'
'Created By:      OneStream Software
'Date Created:    06-01-2016
'---------------------------------------------------------------------------------------

'Get the filename and strip off the Unique ID suffix if it exists
If api.Parser.Transformer.FileInfo.SourceFileName.Contains("_") Then

	'Split filename into segments (Parse by "_" character)
	Dim segments As List(Of String) = StringHelper.SplitString( _
		api.Parser.Transformer.FileInfo.SourceFileName, _
		"_", _
		StageConstants.ParserDefaults.DefaultQuoteCharacter)

	' Create a string builder object,  loop over the segments, 
	' and put the file name back together;
	' skip the last segment, which is the Unique ID suffix.  
	' We use a string builder rather than concatenating with "&",
	' because string builders are much faster.

	Dim segName As New System.Text.StringBuilder

	For seg As Integer = 0 To segments.Count - 2

		segName.Append(segments(seg))

		If seg < (segments.Count - 2) Then

			segName.Append("_")

		End If

	Next

	'Return the contents of the string builder as a string
	Return segName.ToString

Else

	'File name does not contain "_", just return it
	Return api.Parser.Transformer.FileInfo.SourceFileName

End If
Updated 2 years ago
Version 5.0