2

I am trying to move some files from one folder to another, and i Need to evaluate if a file name contains certain text then only we need to move those files.

for example , i have following files in a folder.

abcd_takeme_fdsljker.txt
abcd_file_fdsljker.txt
abcd_takeme_fdsljsdfker.txt
abcd_filetk_fdsljker.txt
abcd_takeme_fdsljssker.txt

from the above I want to pick files which has text "takeme"

Hadi
  • 36,233
  • 13
  • 65
  • 124
vignesh
  • 1,414
  • 5
  • 19
  • 38
  • Possible duplicate of [SSIS Foreach Loop with specific flat files](https://stackoverflow.com/questions/19243893/ssis-foreach-loop-with-specific-flat-files) – Tab Alleman May 25 '17 at 12:46
  • 1
    @TabAlleman i don't think this is a duplicate. It is more general than the question u provided. The OP is asking for any method and have not specified the `Foreach loop` method. It can be achieved using script task or other component. – Hadi May 25 '17 at 13:50

1 Answers1

1

Using For each 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