Rename File in SSIS
August 26th, 2015 1:11am

Hi Vipin,

I am little confused as I am not able to understand the naming rule of your original file, like Vendor_20150820_2484.csv, Vendor_20150821_2484.csv. Does it uses this rule: Vendor_yyyymmdd_2484.csv?

If the original file uses the rule Vendor_yyyymmdd_2484.csv, then we can just use expression to control the ConnectionString property of the Flat File Connection Manager without renaming the file to achieve your requirement. The expression for ConnectionString property is like below:
"C:\\Users\\user_name\\Desktop\\folder_name\\Vendor_"+(DT_WSTR,4)year(getdate())+right("0"+(DT_WSTR,4)month(getdate()),2)+right("0"+(DT_WSTR,4)day(getdate()),2)+"_2784.csv"

If there are any misunderstanding, please elaborate the issue for further investigation.

Thanks,
Katherine Xiong

Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 2:30am

Hi,

You can use below link;

http://beyondrelational.com/modules/2/blogs/70/Posts/18875/exploring-ssis-rename-file-by-suffixing-current-date.aspx

Thanks

August 26th, 2015 2:32am

Hi Vipin,

Below are the approaches you can achieve the above requirement.

Approach1

using System.IO;
using System.Globalization;
Code

string dirctoryPath = "D:\\Anuj\\FILES\\";
            string[] fileEntries = Directory.GetFiles(dirctoryPath);
            foreach (string fileName in fileEntries)
            {
                string oldPath = fileName;
                string fName = Path.GetFileName(fileName);
                string[] words = fName.Split('_');
                // getting all words
                string fileInitial = words[0].ToString();
                string filedate = words[1].ToString();
                string filenum = words[2].ToString();
                string reststring = words[3].ToString();
                var dt = DateTime.ParseExact(filedate,
                                  "yyyyMMdd",
                                   CultureInfo.InvariantCulture);
               
                string newDate = dt.AddDays(1).ToString("yyyyMMdd");
                string newPath = dirctoryPath + fileInitial + "_" + newDate.ToString() + "_" + filenum + "_" + reststring;
                File.Move(oldPath, newPath);
Approach 2
your expression will look like this

@[User::VarArchiveFolder]+"\\"+ Replace( @[User::FileName] ,Replace((DT_WSTR,12)(DT_DBDATE)DATEADD("day", -1, GETDATE()),"-",""),Replace((DT_WSTR,30)(DT_DBDATE) getdate(),"-",""))

Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 2:48am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics

Hi All,

I have a dataflow task that load data from flat file to SQL Table.
In need to rename the file with the  datestamp(current date ) at the end of filename.
I am daily getting a file like Vendor_20150820_2484.csv , 
Vendor_20150821_2484.csv

as the file name getting changed so i can not load data .

i want to change the file name  Vendor_20150820_2484.csv to Vendor_yyyymmdd.csv.

this file I will use to load into sql


Suggestions and Help would be highly appreciated.

Thanks,


Vipin Jha