SSIS to get the particular file from multiple files and copy to different folder - ssis

my question is how we will create SSIS package to get the particular file from multiple files and copy to different folder
Need Help

You can use File System Task in your package control flow.
Configure the properties as below:
DestinationConnection: Enter the full file path of the folder you want to move your file to e.g c:\Users\ToTest
Operation: Change to Move file.
SourceConnection: Enter the full file path of the folder where your file is, including the file name and extension e.g c:\Users\Test\testfile.csv

You'll need at least two components.
Use a Foreach Loop container with the default Foreach File Enumerator on the Collection tab. Set Folder: to \YourFolder and build an expression under Files: to identify the particular file you're interested in.
Inside the Foreach Loop container, add a File System Task to Copy the file from the Source folder to the Destination folder.

Related

ssis renaming a file wthout knowing existing name

I have set up part of my ssis package to check a folder and move the csv file to another folder using a file system task.
Is it possible to rename a file without knowing what the source name will be? as I have been told it will be a new name on a daily bases. can I use a wildcard in a file system task? would I be best renaming before moving what is best practise?
For an unknown file name you can wrap your file system task in a foreach loop
wrap your file system task in a foreach loop and set to file enumerate
set the folder to your source location
set search string to *.csv
set to full file path
map to a variable called fname
use fname as variable in file system task for source
Make sure you delay validation on connection manager

Add headers to multiple text files SSIS

I have a process that I want to create in SSIS. What I have so far is below.
So the scenario is that a number of different file types are downloaded to a specific location - which has been created as a variable "RootFolder"
Within that RootFolder, is a folder called "Archive"
The first part of the process is to create a folder within the variable of ArchiveFolder, which is basically todays date.
Then in a For Loop Container, it copies all the files in the RootFolder to the Archive Folder. So we have a history of the files received.
The next step that I want to carry out in SSIS is to add a header line at the top of each of those text files. So all the files that still exist in the Root Folder get a header added to the top of the file. Is there something direct in SSIS to do this, or would I need a .bat file to do it and have an Execute Process Task, to call that bat file. Either way I have no idea how to achieve this bit. Your help will be appreciated.

SSIS - Delete Unknown-Name Folder Within A Known Directory

I am writing a SSIS package, and at one point I am working with a certain folder that I know the path for, and need to delete a folder inside that, but I don't know the name (path) of the inner folder.
So for example, I know this path: C:\Known, but there will be a folder inside 'Known' that I would like to delete. Like C:\Known\ Unknown
I can't use a File System Task and delete the unwanted folder, because I don't know the name of the folder, and I can't use a File System Task to delete all the directory contents of 'C:\Known', because it also contains .jpeg files that I need to keep.
Any thoughts? A solution to get the name of the Unknown folder, or delete any folders inside 'C:\Known' is acceptable.
You can add this code to a Script Task to delete all subdirectories in a path while not deleting any other file types:
foreach (string subdirectoryPath in Directory.GetDirectories(knownPath, "*", SearchOption.AllDirectories))
{
Directory.Delete(subdirectoryPath);
}

How to dynamically select different config file against different conditions in SSIS?

I want to load different config files for different conditions. for example, if I have "vendor" in my variable value, then load a vendor's config file, similarly for ext_warehouse.
not possible, SSIS will load all the file you specify on the package configuration organizer on the order they are listed and it will use the values on the configuration files to load your variables.
What you could do, lets say you have a "vendors.dtsConfig" and a"customer.dtsConfig", is to create a parent package that read a config file called "parent.dtsConfig" that will only have your variable containing "vendor" or "customer" and based on that value you copy the correct config file to another folder and call the actual package that reads the recently copied (and renamed) file

Recursively navigate a directory generating dynamic xml files according to the current visited folder with SSIS

I need to visit a folder and all of its children with SSIS (SQL Server Integration Services). At the moment by setting the folder path into a variable after reading it, I able to loop through all the .txt files of the current folder and fill a pre-generated (with head info) xml file.
What I would need now is to be able to create one per each accessed folder, a new xml file (the beginning content will be always the same). Once I would be able to create it, as first action once a new folder is accessed, I can then simply apply the logic I developed so far.
However I am blocked at the moment, since within the loop where i read the files (with their full path) I cannot find a way to express "create the xml file if the accessed folder is new".
Assuming I understand the problem, you need to walk the entirety of a directory structure and for each folder you find, you need to create a base XML file. Then for each text file you find in that folder, you will perform some operation on the XML file. The trick being how do you only create the XML file once.
I would envision a process like this.
A script task that makes use of the System.IO.GetDirectories to populate a variable (directoryXML> that contains the folder structure, something like
<Dir>
<D>C:\ssisdata</D>
<D>C:\ssisdata\a</D>
<D>C:\ssidata\a\b</D>
</Dir>
Use a Foreach Nodelist Enumerator to shred that XML out into a variable (currentDirecotry).
You'd perform your one-time task of creating the XML file in currentDirectory.
Further using the currentDirectory variable as an expression on the Foreach File Enumerator (assign to Directory with a FileSpec of *.txt) you can then perform your task on all the files meeting that specification. Do not check the traverse subfolder option as that will not give the desired results.
This is a fairly high level approach to the problem as I'm assuming you have some familiarity with SSIS but the approach should be sound. Let me know if you have any particular sticking points.