<#+ // BimlScript to autogenerate tables and SSIS-packages for loading extract files // By Johan Åhlén 2015 // Settings here... const string directory = @"C:\Johan\Dev\BimlDemo"; const char separator = ';'; const string codepage = "1252"; // ANSI #> <#+ // This class and the list "files" will contain necessary information public class ExtractFileInfo { public string Path; public string FilenameWithoutExtension; public string[] Columns; public bool IsLastColumn(string column) { return column == Columns[Columns.Length - 1]; } } System.Collections.Generic.List files = new System.Collections.Generic.List(); #> <# foreach (var filepath in System.IO.Directory.EnumerateFiles(directory, "*.txt")) { var sr = new System.IO.StreamReader(filepath); var firstRow = sr.ReadLine(); sr.Close(); var efi = new ExtractFileInfo { Path = filepath, FilenameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(filepath), Columns = firstRow.Split(separator) }; files.Add(efi); } #> <# foreach (var file in files) { #> <# foreach (var column in file.Columns) { #> <# } #>
<# } #>
<# foreach (var file in files) { #> <# foreach (var column in file.Columns) { #> " MaximumWidth="4000" /> <# } #> <# } #> <# foreach (var file in files) { #> <# } #> <# foreach (var file in files) { #> <# } #> <# foreach (var file in files) { #> TRUNCATE TABLE [Import].[<#= file.FilenameWithoutExtension #>]; <# } #>