title: copy files from one location to another location using VB and based on created date
body: <p>I am trying to move csv files from one location to another based on create date. </p>
  
  <p>But the code I using in not working it shows error that sample.csv is already being used by another process , how can I resolve this issue ?</p>
  
  <p>this is the error message "Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.IOException: The process cannot access the file 'C:\New folder\Test.txt' because it is being used by another process.
     at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
     at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
     at ST_b8571e8d94a54a80ab50a1e221d93b11.vbproj.ScriptMain.Main()
     --- End of inner exception stack trace ---
     at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct&amp; sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
     at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
     at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, CultureInfo culture)
     at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()"</p>
  
  <pre><code> Public Sub Main()
          Dim csvFilesToday = New List(Of String)
          Dim sourceDir As String = "C:\New folder"
          Dim backupDir As String = "C:\New folder (2)"
  
          For Each csv In Directory.GetFiles(sourceDir, "*.csv", IO.SearchOption.AllDirectories)
              If File.GetCreationTime(csv).Date = Date.Today Then
                  File.Copy(Path.Combine(sourceDir, csv), Path.Combine(backupDir, csv), True)
              End If
          Next
          Dts.TaskResult = ScriptResults.Success
      End Sub
  
  End Class
  </code></pre>