Using a filename to set a variable's value

  • I have a folder, E:\test\, with a zip file. this zip file is in a date format, for example, 01-15-09.zip. Now in two weeks another file will be uploaded and now the zip file will now be 01-31-09.zip. After I've processed the zip file I will move it to another folder that has not been created yet so I want to get the date portion of the filename so I can put it in a variable in order to create a folder with a 01-15-09 name. Is this possible by using a variable to capture the filename and then using that variable as the input to create subfolder which will be "E:\test\01-15-09\"?

  • Yes, this can be done with SSIS.

    Declare a variable, set up a For...Each...Next loop that goes through the files in the folder, and assign the file name to the variable. Use the variable as part of a file-system-object command to create a folder. Very straightforward.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • GSquared (1/23/2009)


    Yes, this can be done with SSIS.

    Declare a variable, set up a For...Each...Next loop that goes through the files in the folder, and assign the file name to the variable. Use the variable as part of a file-system-object command to create a folder. Very straightforward.

    I am getting a "Directory already exist" error message. Here's what I'm doing:

    In the Foreach Loop in the Collection I have in the Folder, the path of where my file is "E:\test" and in the Files i have "*.zip" (without the double quotes). Variable Mappings set the variable to the empty variable, for example, User::ZipFileName variable. When the Foreach Loop gets executed, the *.zip I specified in the collection should get stored in the User::ZipFileName, correct?

    Now inside the Foreach Loop container, I created a File System Task with the following criteria: UseDirectoryIfExists = True, Operation = Create directory, IsSourcePathVariable = True, SourceVariable = User::FileSourcePath (which is the "E:\test"). Nothing is in the expressions. Is this correct?

    Am I missing something else?

  • I guess my main problem is that I can't seem to capture the filename to assign to the variable...I've what I mentioned above and even using a connection string in the Source Connection and nothing seems to work. Can anyone suggest how they would set up a foreach loop to get the file name to put in a variable?

Viewing 4 posts - 1 through 3 (of 3 total)

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