Hi,
Iam trying to copy an executable from Folder A to Folder B.
1. If a back up executable is found in Folder B then delete it. (Example: delete exe1bkp.exe)
2. If an executable without bkp is found then rename it. (Example: "exe1" & "bkp" & ".exe"
3. Copy the new updated executable "exe1.exe" from Folder A to Folder B.
I am using the following code.
VB Code:
  1. Private Sub CopyFolder()
  2. Dim i As Integer, j As Integer, strFile As String, FileName As String, fs
  3. Dim SourceFile, DestinationFile, srcFname, dstFname, fileContent, SearchContent
  4. List3.Clear
  5. Set fs = CreateObject("Scripting.FileSystemObject")
  6. strFile = Dir("C:\TempCafesoftUpdateFolder\exes\*.exe")
  7. While Not Len(strFile) = 0
  8.     List3.AddItem strFile
  9.     For i = 0 To List3.ListCount - 1
  10.         If strFile = List3.List(i) Then
  11.             For j = 0 To List3.ListCount - 1
  12.                 'Delete the file
  13.                 FileName = App.Path & "\bkp" & strFile
  14.                 If (fs.FileExists(FileName)) Then fs.DeleteFile (FileName)
  15.             Next
  16.             DoEvents: DoEvents: DoEvents: DoEvents: DoEvents: DoEvents: DoEvents
  17.             Name App.Path & "\" & strFile As App.Path & "\bkp" & strFile
  18.             srcFname = "C:\TempCafesoftUpdateFolder\exes\" & strFile
  19.             dstFname = App.Path & "\" & strFile
  20.             DoEvents: DoEvents: DoEvents: DoEvents: DoEvents: DoEvents: DoEvents
  21.             Label4.Visible = True
  22.             Label4 = "Copying " & strFile & " to " & App.Path & "\exes"
  23.             DoEvents: DoEvents: DoEvents: DoEvents: DoEvents: DoEvents: DoEvents
  24.             FileCopy srcFname, dstFname
  25.             Label4.Visible = False
  26.         End If
  27.     Next
  28.     strFile = Dir()
  29. Wend
  30. End sub
When FileCopy runs, the program generates an error. What is wrong with this code? Pl help.
Thanks in advance