Try this :-
The Foreach Loop
will enumerate the source folder and the path will be stored in a variable. In the script task
write a code to get the folder Name using regular expression .The script task value will be stored in another variable which will be used in File System Task
The package design will be

In the above expression for DestLoc
variable ,change it as per your location
- ForEach Loop configuration


Change the source folder location as per the need
Example
LoopFiles
variable will have D:\ForLoop\SampleFolder1.txt
at runtime
So in order to extract folder name from the above variable use regular expression
Open Edit Script
and write the following code
List<string> filePatterns = null;
public void Main()
{
filePatterns = new List<string>();
filePatterns.Add("Folder1");
filePatterns.Add("Folder2");
string fileName = Path.GetFileNameWithoutExtension(Dts.Variables["User::LoopFiles"].Value.ToString());
Match match = Regex.Match(fileName, string.Join("|", filePatterns.ToArray()));
Dts.Variables["User::FolderName"].Value = match.Value;
Dts.TaskResult = (int)ScriptResults.Success;
}
In the above code ,you are extracting the folder name and storing it in the variable FolderName
.If you have multiple folders
,then just add the folder names
to the filePatterns
collection variable.
- File System Task Configuration
