Using SSIS to find a dynamic file name...HELP!!!
I am having an issue getting an older script to work now that the file naming convention has been changed for a process. It used to give me a specific name and now it appends the time stamp to the end of the file name; however I never know what the full stamp will be. I have tried to use the GetName() with no success, probably not using it right). A sample file name would be \\network\filedir\Myfile_05_16_2011_05_43.pdf The " \\network\filedir\Myfile_05_16_2011" I can statically determine but the 05_43 (time: 5:43 am) will change according to when the file was actually created. I could really use some help as I am not a VB guru. Here is a sample of the code that I am using to try to get and move the files. Imports System Imports System.Data Imports System.Math Imports System.IO Imports Microsoft.SqlServer.Dts.Runtime Public Class ScriptMain Public Sub Main() ... 'Weekly Roll Up Reports ' First check to see if the file exists, delete existing destination file, and move_rename file to webserver Dim report As String report = Microsoft.VisualBasic.FileIO.FileSystem.GetName("\\MyNetwork\files\") If File.Exists("\\MyNetwork\files\" + report) Then File.Move("\\MyNetwork\files\" + report, "\\OtherServer\files\NewName.pdf") Else End If
May 16th, 2011 6:30pm

Hello, you can use For each loop to achieve this. Here is the link how you will loop through the files in folder http://www.sqlis.com/sqlis/post/Looping-over-files-with-the-Foreach-Loop.aspx Inside the foreach loop , drag Script task, then get the File System Task, Connect both of the task. In precedence contraints you will write your expressions. SUBSTRING(@[User::VarFileName],1,LEN())=="\\YourSERVERNAME\D$\MYFolder\MyFileName" You will replace LEN() with the number of characters for \\YOURSERVERNAME\FOLDER\FILENAME without time stamp. You will only compare the name and if name matched with your criteria then you will move them file , otherwise you will do nothing, or you can delete the file by using another file system task. For the precedence contraints in ssis , please visit following link http://blogs.msdn.com/b/mattm/archive/2006/10/30/using-expression-based-constraints.aspx Thankshttp://sqlage.blogspot.com/
Free Windows Admin Tool Kit Click here and download it now
May 16th, 2011 7:45pm

The other technique you can use inside your script is to use the Directory.GetFiles method. Talk to me now on
May 17th, 2011 12:58pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics