dbTalk Databases Forums  

import multiple files with subdirectories

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss import multiple files with subdirectories in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jason
 
Posts: n/a

Default import multiple files with subdirectories - 11-15-2004 , 10:09 AM






Hi,

I've a testpackage which i'm trying to adjust. What i would like is to
import multiple textfiles (because there are files with the same name) and
archive them.

The package is from sqldts.com so i'll paste the activex scripts:

Script 1 - Defining the Global Variables:

Option Explicit

Function Main()

dim fso
dim fold
dim pkg
dim stpContinuePkg
dim stpExitbadDirectory

' First thing we need to do is to check if our directories are valid.

SET pkg = DTSGlobalVariables.Parent

SET stpContinuePkg = pkg.Steps("DTSStep_DTSActiveScriptTask_3")
SET stpExitBadDirectory = pkg.Steps("DTSStep_DTSActiveScriptTask_2")

DTSGlobalVariables("gv_FileCheckErrors").Value = ""

'We use the FileSystemObject to do our
'Folder manipulation

set fso = CREATEOBJECT("Scripting.FileSystemObject")


'Here we check to make sure the Source folder for the files exists

if fso.FolderExists(DTSGlobalVariables("gv_FileLocati on").Value) <> "True"
then
DTSGlobalVariables("gv_FileCheckErrors").Value =
CSTR(DTSGlobalVariables("gv_FileCheckErrors").Valu e) &_
" " & "Source File directory Not Found"
end if

'Here we check to make sure the Archive folder for the files exists

if fso.FolderExists(DTSGlobalVariables("gv_ArchiveLoc ation").Value) <>
"True" then
DTSGlobalVariables("gv_FileCheckErrors").Value =
CSTR(DTSGlobalVariables("gv_FileCheckErrors").Valu e) &_
" " & "Archive File directory Not Found"
end if

'We predefined the GlobalVariable gv_FileCheckErrors = "" which
'has a length of 2 so we check to see if it has expanded. If it has then
we
'know we had an error and we disable the step that would
'allow us to continue in the package and enable the step
'that takes us out and handles the errors we encountered

If len(DTSGlobalVariables("gv_FileCheckErrors").Value ) > 2 Then
stpContinuePkg.DisableStep = True
stpExitBadDirectory.DisableStep = False
Else
stpContinuePkg.DisableStep = False
stpExitBadDirectory.DisableStep = True

end if

Main = DTSTaskExecResult_Success
End Function
----------------------------------------------------------------------------
------
Script 2 - Bad directories

Option Explicit

Function Main()

Msgbox "You had a Bad Direcory or two please consult: " &_
DTSGlobalVariables("gv_FileCheckErrors").Value

Main = DTSTaskExecResult_Success
End Function
----------------------------------------------------------------------------
------
Script 3 - Looping

Option Explicit

Function Main()

dim pkg
dim conTextFile
dim stpEnterLoop
dim stpFinished

set pkg = DTSGlobalVariables.Parent
set stpEnterLoop = pkg.Steps("DTSStep_DTSDataPumpTask_1")
set stpFinished = pkg.Steps("DTSStep_DTSActiveScriptTask_5")
set conTextFile = pkg.Connections("Text File (Source)")

' We want to continue with the loop only of there are more
' than 1 text file in the directory. If the function ShouldILoop
' returns true then we disable the step that takes us out of the package
' and continue processing

if ShouldILoop = True then
stpEnterLoop.DisableStep = False
stpFinished.DisableStep = True
conTextFile.DataSource = DTSGlobalVariables("gv_FileFullName").Value
stpEnterLoop.ExecutionStatus = DTSStepExecStat_Waiting
else
stpEnterLoop.DisableStep =True
stpFinished.DisableStep = False
stpFinished.ExecutionStatus = DTSStepExecStat_Waiting
End if

Main = DTSTaskExecResult_Success
End Function


Function ShouldILoop

dim fso
dim fil
dim fold
dim pkg
dim counter


set pkg = DTSGlobalVariables.Parent
set fso = CREATEOBJECT("Scripting.FileSystemObject")

set fold = fso.GetFolder(DTSGlobalVariables("gv_FileLocation" ).Value)

counter = fold.files.count

'So long as there is more than 1 file carry on

if counter >= 1 then

for each fil in fold.Files
DTSGlobalVariables("gv_FileFullName").Value = fil.path
ShouldILoop = CBool(True)
Next

else
ShouldILoop = CBool(False)
End if

End Function

----------------------------------------------------------------------------
------
Script 4 - Loop Around


Option Explicit

Function Main()

dim pkg
dim stpbegin
dim fso
dim fil
dim fold

set pkg = DTSGlobalVariables.Parent
set stpbegin = pkg.Steps("DTSStep_DTSActiveScriptTask_3")

set fso = CREATEOBJECT("Scripting.FileSystemObject")

'The trick to looping in DTS is to set the step at the start of the loop to
an execution status of waiting

stpbegin.ExecutionStatus = DTSStepExecStat_Waiting

'This is how we do our archiving. We use the FileSystemObject to move
'the file to another directory
'I extend this even further in my packages and zip the files up as well.
'I do this using the command line zipping tool from PKWare

fso.MoveFile DTSGlobalVariables("gv_FileFullName").Value
,DTSGlobalVariables("gv_ArchiveLocation").Value

Main = DTSTaskExecResult_Success
End Function
----------------------------------------------------------------------------
------
Script 5 - Finishing

Option Explicit

Function Main()

MSGBOX "Package has Completed."

Main = DTSTaskExecResult_Success
End Function

I really need some help with this.



Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: import multiple files with subdirectories - 11-15-2004 , 01:39 PM






So as you lop through then why you archive them can you not prepend the name of the "Found In" directory to the nme of the archived
file?

--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.Konesans.com


"Jason" <jasonlewis (AT) hotrmail (DOT) com> wrote

Quote:
Hi,

I've a testpackage which i'm trying to adjust. What i would like is to
import multiple textfiles (because there are files with the same name) and
archive them.

The package is from sqldts.com so i'll paste the activex scripts:

Script 1 - Defining the Global Variables:

Option Explicit

Function Main()

dim fso
dim fold
dim pkg
dim stpContinuePkg
dim stpExitbadDirectory

' First thing we need to do is to check if our directories are valid.

SET pkg = DTSGlobalVariables.Parent

SET stpContinuePkg = pkg.Steps("DTSStep_DTSActiveScriptTask_3")
SET stpExitBadDirectory = pkg.Steps("DTSStep_DTSActiveScriptTask_2")

DTSGlobalVariables("gv_FileCheckErrors").Value = ""

'We use the FileSystemObject to do our
'Folder manipulation

set fso = CREATEOBJECT("Scripting.FileSystemObject")


'Here we check to make sure the Source folder for the files exists

if fso.FolderExists(DTSGlobalVariables("gv_FileLocati on").Value) <> "True"
then
DTSGlobalVariables("gv_FileCheckErrors").Value =
CSTR(DTSGlobalVariables("gv_FileCheckErrors").Valu e) &_
" " & "Source File directory Not Found"
end if

'Here we check to make sure the Archive folder for the files exists

if fso.FolderExists(DTSGlobalVariables("gv_ArchiveLoc ation").Value)
"True" then
DTSGlobalVariables("gv_FileCheckErrors").Value =
CSTR(DTSGlobalVariables("gv_FileCheckErrors").Valu e) &_
" " & "Archive File directory Not Found"
end if

'We predefined the GlobalVariable gv_FileCheckErrors = "" which
'has a length of 2 so we check to see if it has expanded. If it has then
we
'know we had an error and we disable the step that would
'allow us to continue in the package and enable the step
'that takes us out and handles the errors we encountered

If len(DTSGlobalVariables("gv_FileCheckErrors").Value ) > 2 Then
stpContinuePkg.DisableStep = True
stpExitBadDirectory.DisableStep = False
Else
stpContinuePkg.DisableStep = False
stpExitBadDirectory.DisableStep = True

end if

Main = DTSTaskExecResult_Success
End Function
----------------------------------------------------------------------------
------
Script 2 - Bad directories

Option Explicit

Function Main()

Msgbox "You had a Bad Direcory or two please consult: " &_
DTSGlobalVariables("gv_FileCheckErrors").Value

Main = DTSTaskExecResult_Success
End Function
----------------------------------------------------------------------------
------
Script 3 - Looping

Option Explicit

Function Main()

dim pkg
dim conTextFile
dim stpEnterLoop
dim stpFinished

set pkg = DTSGlobalVariables.Parent
set stpEnterLoop = pkg.Steps("DTSStep_DTSDataPumpTask_1")
set stpFinished = pkg.Steps("DTSStep_DTSActiveScriptTask_5")
set conTextFile = pkg.Connections("Text File (Source)")

' We want to continue with the loop only of there are more
' than 1 text file in the directory. If the function ShouldILoop
' returns true then we disable the step that takes us out of the package
' and continue processing

if ShouldILoop = True then
stpEnterLoop.DisableStep = False
stpFinished.DisableStep = True
conTextFile.DataSource = DTSGlobalVariables("gv_FileFullName").Value
stpEnterLoop.ExecutionStatus = DTSStepExecStat_Waiting
else
stpEnterLoop.DisableStep =True
stpFinished.DisableStep = False
stpFinished.ExecutionStatus = DTSStepExecStat_Waiting
End if

Main = DTSTaskExecResult_Success
End Function


Function ShouldILoop

dim fso
dim fil
dim fold
dim pkg
dim counter


set pkg = DTSGlobalVariables.Parent
set fso = CREATEOBJECT("Scripting.FileSystemObject")

set fold = fso.GetFolder(DTSGlobalVariables("gv_FileLocation" ).Value)

counter = fold.files.count

'So long as there is more than 1 file carry on

if counter >= 1 then

for each fil in fold.Files
DTSGlobalVariables("gv_FileFullName").Value = fil.path
ShouldILoop = CBool(True)
Next

else
ShouldILoop = CBool(False)
End if

End Function

----------------------------------------------------------------------------
------
Script 4 - Loop Around


Option Explicit

Function Main()

dim pkg
dim stpbegin
dim fso
dim fil
dim fold

set pkg = DTSGlobalVariables.Parent
set stpbegin = pkg.Steps("DTSStep_DTSActiveScriptTask_3")

set fso = CREATEOBJECT("Scripting.FileSystemObject")

'The trick to looping in DTS is to set the step at the start of the loop to
an execution status of waiting

stpbegin.ExecutionStatus = DTSStepExecStat_Waiting

'This is how we do our archiving. We use the FileSystemObject to move
'the file to another directory
'I extend this even further in my packages and zip the files up as well.
'I do this using the command line zipping tool from PKWare

fso.MoveFile DTSGlobalVariables("gv_FileFullName").Value
,DTSGlobalVariables("gv_ArchiveLocation").Value

Main = DTSTaskExecResult_Success
End Function
----------------------------------------------------------------------------
------
Script 5 - Finishing

Option Explicit

Function Main()

MSGBOX "Package has Completed."

Main = DTSTaskExecResult_Success
End Function

I really need some help with this.





Reply With Quote
  #3  
Old   
Jason
 
Posts: n/a

Default Re: import multiple files with subdirectories - 11-16-2004 , 01:37 AM



Hi Allen,

I supposed i could, but i don't know how. Can you help me?

J
"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote

Quote:
So as you lop through then why you archive them can you not prepend the
name of the "Found In" directory to the nme of the archived
file?

--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.Konesans.com


"Jason" <jasonlewis (AT) hotrmail (DOT) com> wrote

Hi,

I've a testpackage which i'm trying to adjust. What i would like is to
import multiple textfiles (because there are files with the same name)
and
archive them.

The package is from sqldts.com so i'll paste the activex scripts:

Script 1 - Defining the Global Variables:

Option Explicit

Function Main()

dim fso
dim fold
dim pkg
dim stpContinuePkg
dim stpExitbadDirectory

' First thing we need to do is to check if our directories are valid.

SET pkg = DTSGlobalVariables.Parent

SET stpContinuePkg = pkg.Steps("DTSStep_DTSActiveScriptTask_3")
SET stpExitBadDirectory = pkg.Steps("DTSStep_DTSActiveScriptTask_2")

DTSGlobalVariables("gv_FileCheckErrors").Value = ""

'We use the FileSystemObject to do our
'Folder manipulation

set fso = CREATEOBJECT("Scripting.FileSystemObject")


'Here we check to make sure the Source folder for the files exists

if fso.FolderExists(DTSGlobalVariables("gv_FileLocati on").Value)
"True"
then
DTSGlobalVariables("gv_FileCheckErrors").Value =
CSTR(DTSGlobalVariables("gv_FileCheckErrors").Valu e) &_
" " & "Source File directory Not Found"
end if

'Here we check to make sure the Archive folder for the files exists

if fso.FolderExists(DTSGlobalVariables("gv_ArchiveLoc ation").Value)
"True" then
DTSGlobalVariables("gv_FileCheckErrors").Value =
CSTR(DTSGlobalVariables("gv_FileCheckErrors").Valu e) &_
" " & "Archive File directory Not Found"
end if

'We predefined the GlobalVariable gv_FileCheckErrors = "" which
'has a length of 2 so we check to see if it has expanded. If it has
then
we
'know we had an error and we disable the step that would
'allow us to continue in the package and enable the step
'that takes us out and handles the errors we encountered

If len(DTSGlobalVariables("gv_FileCheckErrors").Value ) > 2 Then
stpContinuePkg.DisableStep = True
stpExitBadDirectory.DisableStep = False
Else
stpContinuePkg.DisableStep = False
stpExitBadDirectory.DisableStep = True

end if

Main = DTSTaskExecResult_Success
End Function

--------------------------------------------------------------------------
--
------
Script 2 - Bad directories

Option Explicit

Function Main()

Msgbox "You had a Bad Direcory or two please consult: " &_
DTSGlobalVariables("gv_FileCheckErrors").Value

Main = DTSTaskExecResult_Success
End Function

--------------------------------------------------------------------------
--
------
Script 3 - Looping

Option Explicit

Function Main()

dim pkg
dim conTextFile
dim stpEnterLoop
dim stpFinished

set pkg = DTSGlobalVariables.Parent
set stpEnterLoop = pkg.Steps("DTSStep_DTSDataPumpTask_1")
set stpFinished = pkg.Steps("DTSStep_DTSActiveScriptTask_5")
set conTextFile = pkg.Connections("Text File (Source)")

' We want to continue with the loop only of there are more
' than 1 text file in the directory. If the function ShouldILoop
' returns true then we disable the step that takes us out of the package
' and continue processing

if ShouldILoop = True then
stpEnterLoop.DisableStep = False
stpFinished.DisableStep = True
conTextFile.DataSource = DTSGlobalVariables("gv_FileFullName").Value
stpEnterLoop.ExecutionStatus = DTSStepExecStat_Waiting
else
stpEnterLoop.DisableStep =True
stpFinished.DisableStep = False
stpFinished.ExecutionStatus = DTSStepExecStat_Waiting
End if

Main = DTSTaskExecResult_Success
End Function


Function ShouldILoop

dim fso
dim fil
dim fold
dim pkg
dim counter


set pkg = DTSGlobalVariables.Parent
set fso = CREATEOBJECT("Scripting.FileSystemObject")

set fold = fso.GetFolder(DTSGlobalVariables("gv_FileLocation" ).Value)

counter = fold.files.count

'So long as there is more than 1 file carry on

if counter >= 1 then

for each fil in fold.Files
DTSGlobalVariables("gv_FileFullName").Value = fil.path
ShouldILoop = CBool(True)
Next

else
ShouldILoop = CBool(False)
End if

End Function


--------------------------------------------------------------------------
--
------
Script 4 - Loop Around


Option Explicit

Function Main()

dim pkg
dim stpbegin
dim fso
dim fil
dim fold

set pkg = DTSGlobalVariables.Parent
set stpbegin = pkg.Steps("DTSStep_DTSActiveScriptTask_3")

set fso = CREATEOBJECT("Scripting.FileSystemObject")

'The trick to looping in DTS is to set the step at the start of the loop
to
an execution status of waiting

stpbegin.ExecutionStatus = DTSStepExecStat_Waiting

'This is how we do our archiving. We use the FileSystemObject to move
'the file to another directory
'I extend this even further in my packages and zip the files up as well.
'I do this using the command line zipping tool from PKWare

fso.MoveFile DTSGlobalVariables("gv_FileFullName").Value
,DTSGlobalVariables("gv_ArchiveLocation").Value

Main = DTSTaskExecResult_Success
End Function

--------------------------------------------------------------------------
--
------
Script 5 - Finishing

Option Explicit

Function Main()

MSGBOX "Package has Completed."

Main = DTSTaskExecResult_Success
End Function

I really need some help with this.







Reply With Quote
  #4  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: import multiple files with subdirectories - 11-16-2004 , 01:40 PM



Of course.

Have a look here

http://msdn.microsoft.com/library/de...stemobject.asp

When you move the file you can prepend thus renaming the file with whatever you want. In your code you will know the directory in
which you sit as you will no doubt pass it as a parameter to the method that iterated the files in the directory.



--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.Konesans.com


"Jason" <jlewis (AT) homail (DOT) com> wrote

Quote:
Hi Allen,

I supposed i could, but i don't know how. Can you help me?

J
"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:e4lQvq0yEHA.1188 (AT) tk2msftngp13 (DOT) phx.gbl...
So as you lop through then why you archive them can you not prepend the
name of the "Found In" directory to the nme of the archived
file?

--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.Konesans.com


"Jason" <jasonlewis (AT) hotrmail (DOT) com> wrote in message
news:OUrxI2yyEHA.1192 (AT) tk2msftngp13 (DOT) phx.gbl...
Hi,

I've a testpackage which i'm trying to adjust. What i would like is to
import multiple textfiles (because there are files with the same name)
and
archive them.

The package is from sqldts.com so i'll paste the activex scripts:

Script 1 - Defining the Global Variables:

Option Explicit

Function Main()

dim fso
dim fold
dim pkg
dim stpContinuePkg
dim stpExitbadDirectory

' First thing we need to do is to check if our directories are valid.

SET pkg = DTSGlobalVariables.Parent

SET stpContinuePkg = pkg.Steps("DTSStep_DTSActiveScriptTask_3")
SET stpExitBadDirectory = pkg.Steps("DTSStep_DTSActiveScriptTask_2")

DTSGlobalVariables("gv_FileCheckErrors").Value = ""

'We use the FileSystemObject to do our
'Folder manipulation

set fso = CREATEOBJECT("Scripting.FileSystemObject")


'Here we check to make sure the Source folder for the files exists

if fso.FolderExists(DTSGlobalVariables("gv_FileLocati on").Value)
"True"
then
DTSGlobalVariables("gv_FileCheckErrors").Value =
CSTR(DTSGlobalVariables("gv_FileCheckErrors").Valu e) &_
" " & "Source File directory Not Found"
end if

'Here we check to make sure the Archive folder for the files exists

if fso.FolderExists(DTSGlobalVariables("gv_ArchiveLoc ation").Value)
"True" then
DTSGlobalVariables("gv_FileCheckErrors").Value =
CSTR(DTSGlobalVariables("gv_FileCheckErrors").Valu e) &_
" " & "Archive File directory Not Found"
end if

'We predefined the GlobalVariable gv_FileCheckErrors = "" which
'has a length of 2 so we check to see if it has expanded. If it has
then
we
'know we had an error and we disable the step that would
'allow us to continue in the package and enable the step
'that takes us out and handles the errors we encountered

If len(DTSGlobalVariables("gv_FileCheckErrors").Value ) > 2 Then
stpContinuePkg.DisableStep = True
stpExitBadDirectory.DisableStep = False
Else
stpContinuePkg.DisableStep = False
stpExitBadDirectory.DisableStep = True

end if

Main = DTSTaskExecResult_Success
End Function

--------------------------------------------------------------------------
--
------
Script 2 - Bad directories

Option Explicit

Function Main()

Msgbox "You had a Bad Direcory or two please consult: " &_
DTSGlobalVariables("gv_FileCheckErrors").Value

Main = DTSTaskExecResult_Success
End Function

--------------------------------------------------------------------------
--
------
Script 3 - Looping

Option Explicit

Function Main()

dim pkg
dim conTextFile
dim stpEnterLoop
dim stpFinished

set pkg = DTSGlobalVariables.Parent
set stpEnterLoop = pkg.Steps("DTSStep_DTSDataPumpTask_1")
set stpFinished = pkg.Steps("DTSStep_DTSActiveScriptTask_5")
set conTextFile = pkg.Connections("Text File (Source)")

' We want to continue with the loop only of there are more
' than 1 text file in the directory. If the function ShouldILoop
' returns true then we disable the step that takes us out of the package
' and continue processing

if ShouldILoop = True then
stpEnterLoop.DisableStep = False
stpFinished.DisableStep = True
conTextFile.DataSource = DTSGlobalVariables("gv_FileFullName").Value
stpEnterLoop.ExecutionStatus = DTSStepExecStat_Waiting
else
stpEnterLoop.DisableStep =True
stpFinished.DisableStep = False
stpFinished.ExecutionStatus = DTSStepExecStat_Waiting
End if

Main = DTSTaskExecResult_Success
End Function


Function ShouldILoop

dim fso
dim fil
dim fold
dim pkg
dim counter


set pkg = DTSGlobalVariables.Parent
set fso = CREATEOBJECT("Scripting.FileSystemObject")

set fold = fso.GetFolder(DTSGlobalVariables("gv_FileLocation" ).Value)

counter = fold.files.count

'So long as there is more than 1 file carry on

if counter >= 1 then

for each fil in fold.Files
DTSGlobalVariables("gv_FileFullName").Value = fil.path
ShouldILoop = CBool(True)
Next

else
ShouldILoop = CBool(False)
End if

End Function


--------------------------------------------------------------------------
--
------
Script 4 - Loop Around


Option Explicit

Function Main()

dim pkg
dim stpbegin
dim fso
dim fil
dim fold

set pkg = DTSGlobalVariables.Parent
set stpbegin = pkg.Steps("DTSStep_DTSActiveScriptTask_3")

set fso = CREATEOBJECT("Scripting.FileSystemObject")

'The trick to looping in DTS is to set the step at the start of the loop
to
an execution status of waiting

stpbegin.ExecutionStatus = DTSStepExecStat_Waiting

'This is how we do our archiving. We use the FileSystemObject to move
'the file to another directory
'I extend this even further in my packages and zip the files up as well.
'I do this using the command line zipping tool from PKWare

fso.MoveFile DTSGlobalVariables("gv_FileFullName").Value
,DTSGlobalVariables("gv_ArchiveLocation").Value

Main = DTSTaskExecResult_Success
End Function

--------------------------------------------------------------------------
--
------
Script 5 - Finishing

Option Explicit

Function Main()

MSGBOX "Package has Completed."

Main = DTSTaskExecResult_Success
End Function

I really need some help with this.









Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.