rename a file

  • i have a file in a folder with extension .ks & .ca ( for example ff10162008.ks , ss10162008.ca)

    I want to rename it to ks.txt & ca.txt

  • Hi,

    If you are looking for solution for this in SSIS, then try exploting File System task in SSIS.

    VG

  • In my opinion, a script task will be easier to understand and maintain for simple tasks like this.

  • Paul

    can u give me sample script task code?

  • Hey Bang.

    If u have multiple files in the same folder, then I would use ForEachLoop and place FileSyatem task to rename it. put your source and destination in a variable and build expression.

    This way you have control over things and packaage will be dynamic too.

    I don't mind other way with the Active-x or Script task, but if there is task that is meant for this, why you wanna write code and have knowledge in the code........

    if u need my solution email me or write the structue of folder, i will post solutions.

  • in a folder

    say c:\source\ all files....

    rename it

    and import

    then again rename

    next time the filename will different but extension will same...

  • I am still confused. Why you trying to rename first? i would import and rename it.

    but anyway......write in more clear in detail for each step...and i will try to post the solution..

  • step 1. will get files in a folder c:\import

    then name of files will be ff10162008.ks , ss10162008.ca

    step 2. rename the file

    ff10162008.ks to ks.txt

    ss10162008.ca to ca. txt

    step3 . import data into table

    ks.txt --- ks table

    ca.txt --- cs table

    step4 . again rename files and archieve it

    ks.txt to ks.txt10202008

    ca.txt to ca.txt10202008

  • Here is your step:

    step 1. will get files in a folder c:\import

    then name of files will be ff10162008.ks , ss10162008.ca

    step 2. rename the file

    ff10162008.ks to ks.txt

    ss10162008.ca to ca. txt

    step3 . import data into table

    ks.txt --- ks table

    ca.txt --- cs table

    step4 . again rename files and archieve it

    ks.txt to ks.txt10202008

    ca.txt to ca.txt10202008

    My question is why you want to rename in Step 2? What purpose does it do renaming in Step 2? Also, Let's say you absolutely need Rename like the way you pointed. SO what if you receive multiple files with same extension. Like.......

    step 1. will get files in a folder c:\import

    then name of files will be ff10162008.ks , ss10162008.ca

    What if you receive another file ff10172008.ks ( i am thinking you only receive one file type at one time) IF not,

    During ur second step you will create a two file with exactly the same name which will override it. (or there is other solution to it too) BUt I see no use of Step 2 here.......If I am not wrong u r using step 2 so that you can make flat file connection with .txt.......

    Follow this step...

    Drag ForEachLoop, Configure it to use it couple of variables -- variable for directory and to hold your filepath value. Bring data follow inside this and make flatfile connection to use the filepath return by foreach loop.

    Then bring file syatem task to rename and arcvhive this........

    If you want me to send you a package for this..........Give me teh folder structure for all .......I will create the package for you and send u in the email.......

  • here is folder structure

    c:/import/data

    after import archieve

    c:/import/archieve

    files are with extension .ks and .ca

    thanks

  • Example file: ff10162008.ks

    Task: Rename to ks.txt

    Sample script task code (untested):

    Dim fileName As String = "c:\cff10162008.ks"

    'Get the file extension (this will be ".ks")

    Dim extension As String = System.IO.Path.GetExtension(fileName)

    'Remove the leading "." and append ".txt"

    Dim newFileName As String = extension.Remove(0, 1) & ".txt"

    My.Computer.FileSystem.RenameFile(fileName, newFileName)

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply