title: Check file in destination folder if exist
body: <p>I am trying to determine the number of files that would be copied from the source folder to the destination and then assign this value to the progressbar.max.But using the code below I get Runtime error 5, Invalid procedure call or argument at the marked position.Please Guide</p>
  
  <pre><code>Private Sub cmdCopy_Click()
  Dim sFileName As String    'Source File
  Dim sDirName As String     'Source Directory
  Dim dDirName As String     'Destination Directory
  Dim fiFileCount As Integer 'Number of Files to be copied
  Dim fbFileMatch As Boolean
  
  If prgFCount.Visible = True Then prgFCount.Visible = False
  
  dDirName = "D:\Destination\"
  sDirName = "C:\Source\"
  sFileName = Dir(sDirName)
  
  
  ' Disable this button so the user cannot
  ' start another copy.
  cmdCopy.Enabled = False
  cmdCancel.Enabled = True
  fiFileCount = 0
  
  Do While Len(sFileName) &gt; 0
  fbFileMatch = False
  If Len(Dir$(dDirName &amp; sFileName)) &gt; 0 Then
  fbFileMatch = True
  End If
  If fbFileMatch = False Then
  fiFileCount = fiFileCount + 1
  End If
  
  sFileName = Dir '## Error at this Point ##
  Loop
  If fiFileCount = 0 Then
  cmdCopy.Enabled = True
  cmdCancel.Enabled = False
  Exit Sub
  End If
  prgFCount.Min = 0
  prgFCount.Max = fiFileCount
  prgFCount.Visible = True
  End Sub
  </code></pre>