-
Help with WHILE loop
I have a .7z file that always has problems when I try to copy the file via code. This happens with every .7z file that I have tested with. Therefore, I have written the following code to keep repeating a file copy function until the filesize of the destination file matches the size of the source file. However, I think this is getting caught in an endless loop. FYI, file MYFILE.7z already exists on both the source and the destination. The code below is a routine that is executed after the file is in both places to verify that the file actually copies successfully to the destination.
Code:
Public Sub Load_BackupFile()
Dim Device As String
Dim Source7z As Long
Dim Dest7z As Long
Device = Trim(frmmain.cmbDriveSelect.Text)
'get the file size of the .7z file in the build directory & on the Device
source7z = GetFileSize("C:\MYFILE.7z")
Dest7z = GetFileSize(frmmain.cmbDriveSelect.Text & "MYFILE.7z")
While Dest7z <> Source7z
System.IO.File.Copy("C:\MYFILE.7z", Device & "MYFILE.7z", True)
End While
End Sub
And here is the declared function I am using for GetFileSize:
Code:
Public Function GetFileSize(ByVal MyFilePath As String) As Long
Dim MyFile As New FileInfo(MyFilePath)
Dim FileSize As Long = MyFile.Length
Return FileSize
End Function
Thanks for any help with this one.
-Jeremy
-
Re: Help with WHILE loop
Have you checked to see that when you manually copy a .7z file it keeps the exact same size?
-
Re: Help with WHILE loop
Yes, the manual copy works fine. Issue is very strange.
-
Re: Help with WHILE loop
Check to make sure that the end of your path contains a backslash. That is most likely your problem.
Code:
StrPath = frmmain.cmbDriveSelect.Text
If right(StrPath,1) <> "\" Then
Strpath &= "\"
End If
-
Re: Help with WHILE loop
Use this to combine parts of a path
IO.Path.Combine(drctry, filenm)
and try this for your copy
My.Computer.FileSystem.CopyFile(src, dst, overwrite:=True, showUI:=True, onUserCancel:=True)