Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Using a filename to set a variable's value Expand / Collapse
Author
Message
Posted Friday, January 23, 2009 11:19 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, September 24, 2013 5:00 PM
Points: 50, Visits: 161
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\"?
Post #642672
Posted Friday, January 23, 2009 11:30 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 1:09 PM
Points: 13,872, Visits: 9,597
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
Post #642678
Posted Friday, January 23, 2009 2:56 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, September 24, 2013 5:00 PM
Points: 50, Visits: 161
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?
Post #642814
Posted Friday, January 23, 2009 4:44 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, September 24, 2013 5:00 PM
Points: 50, Visits: 161
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?
Post #642841
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse