rename the file one by one using for loop container

  • Hi SSiS gurus,

    i need a package that will read the files inside the folder one by one and rename it insde the for loop container.

    Thanks

    murali

  • Do you need to examine the filenames before renaming them? If so, you'll probably need a script task to do it. If not, you can use the file system task to rename the files.

    Is the only purpose of the loop container to rename the files? If so, I'd just use a script task since the code would be quite simple to read the filenames from a directory, loop through each one, and rename them.

  • Hi Paul,

    i tried using For each loop Container and file system task below is the what i have done in tasks

    foreach loop container:

    -----------------------

    enumerator: for each file enumerator

    folder = d:\sample\renamefiles

    files = *.txt

    variables mapping = user::myfilevalue

    file system task:

    ----------------

    isdestinationpathvariable = true

    destinationvariable = User::fulldestpathfilename

    operation = rename

    issourcepathvariable = true

    sourcevariable = User::fullsourcepathfilename

    variables:

    ----------

    myfilevalue = file1.txt

    dest path = d:\sample\renamefiles

    source path = d:\sample\renamefiles

    fullsourcefilepathname = d:\sample\renamefiles\file1.txt

    fulldestfilepathname = d:\sample\renamefiles\file1_Processed.txt

    it rename only file1.txt into file1_Processed.txt

    but in my d:\sample\renamefiles folder some files also there like file2,file3,file4 etc. i want to change all files one by one

    thanks

    murali

  • and it showed below error:

    SSIS package "Package.dtsx" starting.

    Error: 0xC002F304 at File System Task, File System Task: An error occurred with the following error message: "Could not find file 'D:\sample\rename files\file1.txt'.".

    Warning: 0x80019002 at File System Task: The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.

    Task failed: File System Task

    Warning: 0x80019002 at Foreach Loop Container: The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.

    Warning: 0x80019002 at Package: The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.

    SSIS package "Package.dtsx" finished: Failure.

  • Seems to be looking for "file1.txt" again for some reason. Are you updating the value of the variable holding the name of the file to next rename?

  • Hi Paul,

    i cant understand what u said

    plz tell me breifly.and what i did is correct or not

    thanks

    murali

  • Hi all,

    i have done above requirement but it show in my destfolder like this

    file1-92008.txt,file2-92008.txt...etc

    for above rename i implement expression in fulldestfilepathname

    @[User::destPath] + SUBSTRING( @[User::MyFileValue] , 1 , FINDSTRING( @[User::MyFileValue],".",1) - 1 ) + "-" + (DT_STR, 2, 1252) Month( @[System::StartTime] )+ (DT_STR, 4, 1252) Year( @[System::StartTime] )+ SUBSTRING( @[User::MyFileValue] , FINDSTRING( @[User::MyFileValue],".",1) , LEN( @[User::MyFileValue] ) )

    but i want file1_Proccessed.txt,file2_Processed.txt...etc in destfolder what i have to for this

    any help appriciated

    thanks

    murali

Viewing 7 posts - 1 through 6 (of 6 total)

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