cheryl9063
asked on
SSIS script task
How do you write a VB script that looks in a folder and finds only the files that where added today?
ASKER
thanks..what does that mean..Echo.objFileName? Can I put that before my FileSystemTask? My fileSystemTask uses variables that have the source and destination folders and look for *.* files.. How should I do this? This is all in a For Loop Container
Sorry, here is a working version:
dim objFSO:Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
dim objFile:Set objFile = objFSO.GetFile("x.vbs")
IF left(objFile.DateCreated, instr(objFile.DateCreated, " ")-1) = left(Now(), instr(Now(), " ")-1) THEN
Wscript.Echo objFile.Name & " Created Today."
END IF
dim objFSO:Set objFSO = CreateObject("Scripting.Fi
dim objFile:Set objFile = objFSO.GetFile("x.vbs")
IF left(objFile.DateCreated, instr(objFile.DateCreated,
Wscript.Echo objFile.Name & " Created Today."
END IF
instead of GetFile("x.vbs") you would use the filename from your FOR loop, so...
for MyNextFileName ...
dim objFile:Set objFile = objFSO.GetFile(MyNextFileName)
for MyNextFileName ...
dim objFile:Set objFile = objFSO.GetFile(MyNextFileName)
ASKER
thanks.. see my question before.. Sorry just little experience with this
ASKER
then I connect it to the File system task?
Post your script and I will modify it to find only files created on today's date. (Change any sensitive stuff like IPs or passwords before you post it here though.)
ASKER
ok, stupid question.. How do I send it to you? It has the extension of dtsx which is not in the list of accepted extensions on this site..
oh, I thought this was a VBScript question, no? I don't know what .dtsx is either. If it is VBScript, just copy/paste the portion that retrieves the *.* files (in the FOR loop) here. No need to attach a file, just copy/paste will do.
ASKER
Sorry.. its a SSIS package,, there is no code.. its just a Forloop container that has a variable for the source and one for destination with a file system task in it.
ASKER
I get all kinds of errors in the integration services script task,,
Public Sub Main()
Dim objFSO : objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Dim objFile : objFile = objFSO.GetFile("x.vbs")
If Left(objFile.DateCreated, InStr(objFile.DateCreated, " ") - 1) = Left(Now(), InStr(Now(), " ") - 1) Then
Wscript.Echo(objFile.Name & " Created Today.")
End If
Dts.TaskResult = ScriptResults.Success
End Sub
Public Sub Main()
Dim objFSO : objFSO = CreateObject("Scripting.Fi
Dim objFile : objFile = objFSO.GetFile("x.vbs")
If Left(objFile.DateCreated, InStr(objFile.DateCreated,
Wscript.Echo(objFile.Name & " Created Today.")
End If
Dts.TaskResult = ScriptResults.Success
End Sub
ASKER
the errors are variable declarations without an As clause type of object assumed.. this is on the declarations.. then on the Wscript part I get name not declared... Are you doing this for SSIS?
What I posted was just a sample VBS script to show generically how to identify files created on the current date.
Particularly, the Wscript.Echo statement just does what it says, it echos the matching filenames -- it is a sample statement and has no use in your SSIS code.
Also, you can't use "x.vbs" , that was just my sample file name. In its place (in a real VBScript) you would put the variable that contains the filename like GetFile(myFileVariable)
Finally, I'm guessing the declaration messages are just warnings.
Sorry, my initial understanding of your question was limited in scope and I did not take SSIS into account:
"How do you write a VB script that looks in a folder and finds only the files that where added today?"
Particularly, the Wscript.Echo statement just does what it says, it echos the matching filenames -- it is a sample statement and has no use in your SSIS code.
Also, you can't use "x.vbs" , that was just my sample file name. In its place (in a real VBScript) you would put the variable that contains the filename like GetFile(myFileVariable)
Finally, I'm guessing the declaration messages are just warnings.
Sorry, my initial understanding of your question was limited in scope and I did not take SSIS into account:
"How do you write a VB script that looks in a folder and finds only the files that where added today?"
You may want to have this question deleted and re-post a new one with more details about what you need.
User Script task.
Or have some other tool to compare to folders. Using that get the new files and copy them using File System Task.
Or have some other tool to compare to folders. Using that get the new files and copy them using File System Task.
That's true - you can have a batch script or VB script that copies today's files to a separate folder, then your SSIS package can use that folder. Let us know if you need help with this.
ASKER
Yes I do need help.. How do I copy only the files I need from one folder to another? The files I need are only the ones created today.. for each day..It would be awesome if someone could create a sample one to show me.
Where are the files now (what folder are they in)? ... and where would you like to copy the files created today? (to what folder)
ASKER
Folder1 has hundreds of files with an extension like .P10121302 etc..every day new files are added with different extensions.. I need to move the files created today to a new folder called folder 2.
ASKER
Folder1 has hundreds of files with an extension like .P10121302 etc..every day new files are added with different extensions.. I need to move the files created today to a new folder called folder 2.
understood, but if you provide the full path the script I give you will require less modification. Would you be able to translate from the generic to the specific if I used this in the script?
C:\Parent Folder\Folder1
C:\Parent Folder\Folder2
C:\Parent Folder\Folder1
C:\Parent Folder\Folder2
ASKER
Absolutely...thank you spool much
ASKER
Absolutely...thank you sooo much!
Before I post I need to verify your default system date format. Please run the following command from a command prompt and post the result here:
echo %date%
thanks
echo %date%
thanks
Assuming the results of the above is this (U.S.): Fri 06/03/2011
... then the following code should be saved as a .bat file and scheduled to run automatically just before your SSIS task runs:
@echo off
setlocal
set SOURCEFOLDER="C:\Parent Folder\Folder1"
set DESTINATIONFOLDER="C:\Pare nt Folder\Folder2"
set FILESPEC="*.txt"
cd/d %SOURCEFOLDER%
for /f "tokens=5,*" %%F in ('dir/tw/a-d %FILESPEC% ^| findstr "%date:~4%"') do copy "%%F" %DESTINATIONFOLDER%
... then the following code should be saved as a .bat file and scheduled to run automatically just before your SSIS task runs:
@echo off
setlocal
set SOURCEFOLDER="C:\Parent Folder\Folder1"
set DESTINATIONFOLDER="C:\Pare
set FILESPEC="*.txt"
cd/d %SOURCEFOLDER%
for /f "tokens=5,*" %%F in ('dir/tw/a-d %FILESPEC% ^| findstr "%date:~4%"') do copy "%%F" %DESTINATIONFOLDER%
change the value of the three variables to suite your needs.
ASKER
Thanks! Sorry its taking some time.. got pulled away but I sincerely appreciate your help.
Fri 06/03/2011
Fri 06/03/2011
ASKER
I saved the below as a .bat file. It has the real folder names now and then I ran it.. The files from today did not move?
@echo off
setlocal
set SOURCEFOLDER="G:\DataProce ssing\Plt1 5\Lexicent \Tickets\t emp"
set DESTINATIONFOLDER="G:\ADP\ Plt15\Lexi cent\Ticke ts\testing "
set FILESPEC="*.txt"
cd/d %SOURCEFOLDER%
for /f "tokens=5,*" %%F in ('dir/tw/a-d %FILESPEC% ^| findstr "%date:~4%"') do copy "%%F" %DESTINATIONFOLDER%
@echo off
setlocal
set SOURCEFOLDER="G:\DataProce
set DESTINATIONFOLDER="G:\ADP\
set FILESPEC="*.txt"
cd/d %SOURCEFOLDER%
for /f "tokens=5,*" %%F in ('dir/tw/a-d %FILESPEC% ^| findstr "%date:~4%"') do copy "%%F" %DESTINATIONFOLDER%
Did you change the FILESPEC variable? What type if files are in the SOURCE folder?
ASKER
I did.. I'm new here (third day) but I think its a CSV.. Im attaching one (with a .txt) on the end so I can attach it to this site but its not a .txt.. So take the .txt off and that is what the file is.
LEXICENT.P11060301.txt
LEXICENT.P11060301.txt
ASKER
Its an unknown file type.. used by a web page..
ASKER
so I changed it to *.* and now it works.. So i just need to add that to the Forloop and forget the script task correct?
The idea is to run the .bat file separately to move today's files to Folder2, and then run the SSIS package which operates on the files in Folder2. Once the files have been processed they should be deleted from Folder2 (presumably). Or, if there is an SSIS task that can run .bat scripts, then you can include this as part of the SSIS package.
Also, if you want to "move" the files instead of "copy" them, just change the word copy to move in the .bat script.
Also, if you want to "move" the files instead of "copy" them, just change the word copy to move in the .bat script.
ASKER
Ok so you are awesome!..when I get done rebooting I will close this and give points. Thanks so much..you saved my first week on the job!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect solution
dim objFSO:Set objFSO = CreateObject("Scripting.Fi
dim objFile:Set objFile = objFSO.GetFile("c:\MyFile.
IF objFile.DateCreated = Today THEN
Wscript.Echo objFile.FileName