SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Using a filename to set a variable's value


Using a filename to set a variable's value

Author
Message
mrtrich99
mrtrich99
SSChasing Mays
SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)

Group: General Forum Members
Points: 652 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\"?
GSquared
GSquared
SSC Guru
SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)SSC Guru (94K reputation)

Group: General Forum Members
Points: 94629 Visits: 9730
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
mrtrich99
mrtrich99
SSChasing Mays
SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)

Group: General Forum Members
Points: 652 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?
mrtrich99
mrtrich99
SSChasing Mays
SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)SSChasing Mays (652 reputation)

Group: General Forum Members
Points: 652 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?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search