SSIS Foreach loop through text files with "crosswlk" in the name - sql-server

In my Foreach loop I only want to process files that have crosswlk in the filename. Unfortunately this is in the middle of the filename and I can't do crosswlk.pgp.
I have Googled this a bunch and most solutions say to do some C# in a script task to accomplish this. It seems like I should be able to do this in the Foreach container, maybe in the Collection area with Expressions. But I'm having troubles finding any information about the various Properties in the Property Expressions Editor. What's the difference between the Name, FileSpec and FileNameRetrieval properties?
I thought I could do something like:
Property: Name
Expression: `FINDSTRING(#[User::SourceFilename],"crosswlk",1) > 0`
To me that's saying only process files where the filename has crosswlk in it. But that's not working. I did notice the word crosswlk always starts at the 13th character in the filename so I tried using substring, but no luck there either.
Is there a way to do filter the filenames this (or another) way, or is using C# the only way? Thanks very much!

According to the documentation, you should be able to use wildcards in the Files field.
Use wildcard characters (*) to specify the files to include in the
collection. For example, to include files with names that contain
“abc”, use the following filter: *abc*.
So, you should be able to use something like this: *crosswlk*
See here for more detail: https://learn.microsoft.com/en-us/sql/integration-services/control-flow/foreach-loop-container#enumerator-dynamic-options

If it is too hard to craft a usable wildcard then one option that might be of use is to use a FOREACH ADO Enumerator. First you "fill" a recordset Object Variable with all the filenames you want then you can loop through this.
You can fill the recordset object through a Script Task and use C# system.IO for interrogating the filesystem.
This is a handy way if you need to tightly control what files are processed (eg to prevent test files being loaded)

Related

COPY INTO SNOWFLAKE IGNORE "/"

I wish to upload a file with field with text containing "\", but to ignore it while running COPY INTO.
e.g:
For the following field value: \"before!!\' not!!
I wish the data be loaded as :
"before!!' not!!
I have tried including ESCAPE='\\', Tried using FIELD_OPTIONALLY_ENCLOSED_BY='"',
and ESCAPE_UNENCLOSED_FIELD in all kind of variations, None of those options did the job.
Does anyone have any idea?
Thanks!
If you want to change the values of a field then you would need to do it as part of the SELECT statement e.g. using the REPLACE function.
This is documented here

concatenate inside indirect excel formula

I've been looking for some way to dynamically reference another workbook of excel using concatenate and indirect. And just get more and more frustrated.
This is how my problem looks like.
Concatenate inside Indirect formula
How do I make my formula in cell 'B3' work?
From the picture it appears that you are missing an apostrophe at the beginning of your reference. It should look like this:
'D:\path\[Filename.xlsx]sheet 1'!$D$6
#REF! might as well be caused by just wrong filename. Please check it.
And finally: the referenced file must be open for this formula to work. Do not use INDIRECT() to extract data from other files stored somewhere in system - this is not possible and should be avoided because file references generated from text strings cannot be tracked from Data / Edit Links menu. You should consider using regular formula links to other files instead - you can easily refresh your references from said menu.

Foreach Loop Container failed to traverse through all files in a folder

I have one temp folder C:\Mydata inside that i have .csv files with name
demo1.csv demo2.csv...etc
Now I want to insert data from all those files into database table
for this I have taken Foreach Loop Container in the property Directory I mention
C:\Mydata
inside Foreach Loop Container taken a Data Flow Task in that Flat File Source is there in the connection manager property in file name what should I mention, so that it will traverse through all folder and all files whose extension is .csv
I did like C:\DEMO\*.csv which is giving me error :
no file found path is wrong
From what i interpreted, your issue was assigning the resulting file from the foreach to the connector.
To do that you need to assign the filename from the Foreach to a variable.
The first step to be taken is to create the variable. To do that you need to activate the "Variables" window:
Then you need to create a new variable of type string and rename it.
For more information on SSIS variables and how to create them, see http://msdn.microsoft.com/en-us/library/ms140216.aspx
Now you need to assign the new variable (in this case i named it "filename") to the foreach loop:
NOTE THAT WHILE THE OPTION "Name Only" IS SELECTED IN THE FIRST WINDOW, IN YOUR CASE YOU PROBABLY WANT "Fully Qualified"!!
The screenshot was taken from a working project i have and i am using only the name (Name Only) as opposed to the full path (Fully Qualified)
After doing that you need to assign that variable to your flat file connector using expressions:
Which version of MSSQL and SSIS are you using? And why are you using C:\Mydata in one place and C:\DEMO in another?
The basic technique of looping over files is described here.
There is lot of information about these steps in the documentation and on the web. If you need more help, please be as specific as possible about what you've tried, what isn't working, what versions you're working with etc.

ClearCase config spec selection based on element attribute

In a ClearCase config spec, is it possible to select versions based on element attributres (not version attributes)? For instance:
element * ...{SOME_ELEM_ATTR==SOME_VALUE&&lbtype(MY_LABEL1)}
This doesn't work because the last part of the "element" spec is a version-selector, which only looks at version attributes.
What I'm trying to do is partition my files into two or more classes, and have different "element" lines apply to different classes of files. I tried tagging all the elements in one class with an attribute, but hit a dead end with trying to base the selection on that in the config spec. The only way I can see to do this sort of thing is to put all the files of one class in one place and use the second construct (the "pattern") to differentiate:
element .../all_class1_files/... MY_LABEL1
but this is really ugly because you have to move all the files of one class into one place, or have a giantic config spec listing all the individual directories and/or files.
Thanks in advance...
Ray
One first solution would be to replace the attribute criteria by a branch.
That way, you would more easily be able to label all files from one branch or another, instead of "all files with a given attribute".
Other than this workaround, you will find some find command based on attribute here (or in the man page).
You could then combine a find query with an "-exec" directive to put the label that you want.
That way, you don't have to mess with the config spec syntax (which may not support the exact selection criteria you are after).
I didn't test it, but you could try
element * ...{SOME_ELEM_ATTR==SOME_VALUE && lbtype_sub(MY_LABEL1)}
, because lbtype_sub is an element, branch and version selector (whereas lbtype is just a version selector).
However, since lbtype doesn't seem to be part of the config spec criteria, I doubt it can work in said config spec.
I think I've up with a good solution using "trtype" as a selection criterion (appears to be the only query function that inherits from the element to the version). If the Class1 and Class2 elements have dummy triggers Class1Files andClass2Files attached to them, respectively, then something like
element * .../{trtype(Class1Files)&&lbtype(MY_LABEL1)}
element * .../{trtype(Class2Files)&&lbtype(MY_LABEL2)}
should do the trick. This selects files in Class1 with MY_LABEL1 and in Class2 with MY_LABEL2. I haven't actually tried this out yet, but I'll let you know how this works out.

File Path Control

How to put a File path control in VBA front panel? I want the user to be able to select the browse button and select the file path rather than putting up dialog boxes all over the place. I need the user to select three or more file paths.
After re-re-reading your Q, it seams you want to steer away from dialog boxes!Oh well, I was going to say
I could post the hack about using MSDIAG on VBA, that explains
how you can patch your registry to
enable its use under VBA,
without having other MS-VB products
installed... but I rather have you
google that one... you can certainly
understand why.
But you don't want Dialog Boxes... you want controls and buttons: Use listboxes!
To populate your listbox, use the Dir command (using method additem of the listbox).
Two phases for achieving that:
first get the Directories (and prefix a "->" or whatever prior to adding it on the listbox, so that the user understands this is not a file);
then get filenames (you can filter by extension with the arguments of Dir, just as you would in DOS).
Finally, under OnClick and OnDoubleClick of the listbox, you must interpret the listbox default property (Item), check for "->" and use ChDir to change directory and repopulate, or you'll have your file selected.
The write up is sooooooo much more complicated than the code... trust me.
Do you mean VBA for Microsoft Office or just general VBA?
In Office, Application.FileDialog(msoFileDialogOpen).
Otherwise, look at the Win32 API function SHBrowseForFolder (in shell32.dll). You can import it for use into VBA using the Declare Function keywords.
There is not direct VBA function for that. You can decide to combine a form (Access form, or a generic microsoft form) with 2 controls: (1) text box (2) browse button (which will finally use the fileDialog command or a windows API).
Perhaps the browse for folder API from the Microsoft MVPs site would suit:
http://www.mvps.org/access/api/api0002.htm
It uses SHBrowseForFolder mentioned by fwzgekg, and does not return a file dialog, it returns a browsable list of folders.
Is this what you want?
FilePath = Application.GetOpenFilename

Resources