1

How to move multiple excel files to different folders based on file name in ssis? means based on the file name it will move to respective folder.

Hadi
  • 36,233
  • 13
  • 65
  • 124
Ajit Kumar
  • 107
  • 1
  • 6
  • What have you done so far? – Nick.Mc Jun 29 '17 at 06:54
  • i added a foreach loop container with script task and i am stuck in script task only. @Nick.McDermaid – Ajit Kumar Jun 29 '17 at 07:05
  • A script task is not neccesary but if you like C# it might be your best option. Alternatively I suggest you read this http://www.sqlyoga.com/2014/09/sql-server-ssis-rename-and-move-files.html and come back with _specific_ questions – Nick.Mc Jun 29 '17 at 07:59
  • without script task can we do this with any other task? please suggest me. – Ajit Kumar Jun 29 '17 at 08:02
  • Seems like you didn't read my link – Nick.Mc Jun 29 '17 at 08:13
  • It is moving to only one archive folder but i want based on file name it will move to respective folder. – Ajit Kumar Jun 29 '17 at 08:18
  • It seems you need to alter the expression to do that for you. You haven't actually explained the rule that you want to use. Please edit your question and explain what you've tried, explain the rule you want to use, and show some examples. – Nick.Mc Jun 29 '17 at 08:47

2 Answers2

0

Have you tried this?

In this you can see that you have to create a foreach loop, a script task a and a file system task to move the files to destination folder.

how to move files to different folders , based on matching filename and foldername in ssis

0

Using Foreach loop container

  1. You have to add a for-each loop container to loop over files in a specific directory.

  2. Choose the follow expression as a filename:

    *takeme*

  3. Map the filename to a variable

  4. Add a dataflow task inside the for each loop to transfer files
  5. use the filename variable as a source

you can follow the detailed article at:

if you want to add multiple filter follow my answer at:

Using a script task

or you can achieve this using a script task with a similar code: (i used VB.Net)

Public Sub Main()

    For Each strFile As String In IO.Directory.GetFiles("C:\New Folder\", "*takeme*", IO.SearchOption.AllDirectories)

        Dim filename As String = IO.Path.GetFileName(strFile)

        IO.File.Copy(strFile, "D:\New Folder\" & filename)

    Next

    Dts.TaskResult = ScriptResults.Success
End Sub
Hadi
  • 36,233
  • 13
  • 65
  • 124