I'm taking the first steps in this tool and would like to copy a set of excel files from one folder to another. The source folder has a set of files with suffix YYYYMM, and I will have to copy only the files of the desired month (dependent variable of a query to BD).
The source folder contains several excel file names with "prefix_name_YYYYMM.xlsx", and the prefixes will be available in a txt file or possibly an excel (which is easier to implement!).
I've read some articles on "Foreach Loop Container" and "File System task" for all files in a folder.
But I cannot imagine how I'll get the various file names / prefixes to feed the Loop and get all the files prefix1_YYYYMM _ *. XLSx
Note: the client doesn't want to populate a sql server table with the "prefix file list".
if you want to get the various file names / prefixes to feed the Loop use c# code in the Script task
string SourceDirectory = Dts.Variables["User::varSourceFolder"].Value.ToString();
string[] fileEntries = Directory.GetFiles(SourceDirectory);
foreach (string fileName in fileEntries)
{.....}
This can be achieved by using a File System Task within a Foreach Loop. The following steps outline this further. A couple things to note on the File System Task, you'll need to set DelayValidation
to true, and if you intend to copy new files that will replace old ones then OverwriteDestination
will also need to be set to true.
*
to get all files with this prefix. For example, prefix_name_YYYYMM*.xlsx. IsSourcePathVariable
to true, then add the same variable used in the mapping of the Foreach Loop as the SourceVariable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.