in short the program I have is a file copy application... it reads a file name and path from a given txt file and it does a dlg_open on that file to get the string necessary... however if that file contains a carriage return at the end, I get an error saying there are illegal characters in the path... I would like it to ignore any CRs obviously.
The code I currently have looks like this:
Expand|Select|Wrap|Line Numbers
- #Region " Local variables"
- Private dbl_PctDone As Double = 0
- Private str_SourceFile As String = ""
- Private str_DestFile As String = ""
- Private str_ShortFileName As String = ""
- Private int_CurrentBytes As Long = 0
- Private int_TotalBytes As Long = 0
- #End Region
- #Region " Public Properties"
- Public Property PercentDone() As Double
- Get
- Return dbl_PctDone
- End Get
- Set(ByVal value As Double)
- dbl_PctDone = value
- End Set
- End Property
- Public Property SourceFile() As String
- Get
- Return str_SourceFile
- End Get
- Set(ByVal value As String)
- str_SourceFile = value
- End Set
- End Property
- Public Property DestinationFile() As String
- Get
- Return str_DestFile
- End Get
- Set(ByVal value As String)
- str_DestFile = value
- End Set
- End Property
- Public Property CurrentBytes() As Long
- Get
- Return int_CurrentBytes
- End Get
- Set(ByVal value As Long)
- int_CurrentBytes = value
- End Set
- End Property
- Public Property TotalBytes() As Long
- Get
- Return int_TotalBytes
- End Get
- Set(ByVal value As Long)
- int_TotalBytes = value
- End Set
- End Property
- Public ReadOnly Property ShortFileName() As String
- Get
- Return str_ShortFileName
- End Get
- End Property
- #End Region
- #Region " Private Methods"
- Private Function CopyProgress(ByVal totalFileSize As Int64, ByVal totalBytesTransferred As Int64, ByVal streamSize As Int64, ByVal streamBytesTransferred As Int64, ByVal dwStreamNumber As Int32, ByVal dwCallbackReason As Int32, ByVal hSourceFile As Int32, ByVal hDestinationFile As Int32, ByVal lpData As Int32) As Int32
- Try
- '*** Update the properties and the percentage
- int_CurrentBytes = totalBytesTransferred
- int_TotalBytes = totalFileSize
- dbl_PctDone = Convert.ToInt32((totalBytesTransferred / totalFileSize) * 100)
- Catch
- ThrowError(Err, System.Reflection.MethodBase.GetCurrentMethod.Name)
- End Try
- End Function
- #End Region
- #Region " Public Methods"
- Public Sub New(ByVal SourceFile As String, ByVal DestinationFile As String)
- str_SourceFile = SourceFile
- str_DestFile = DestinationFile
- End Sub
- Public Sub StartCopying()
- Dim cpr As CopyProgressRoutine
- Try
- '*** Set the event handler for the copy progress
- cpr = New CopyProgressRoutine(AddressOf CopyProgress)
- '*** Make sure the file exists
- If File.Exists(str_SourceFile) Then
- '*** Get the file info
- Dim file_Info As New FileInfo(str_SourceFile)
- str_ShortFileName = file_Info.Name
- '*** Start copying the file
- CopyFileEx(str_SourceFile, str_DestFile, cpr, 0, 0, 0)
- End If
- Catch
- ThrowError(Err, System.Reflection.MethodBase.GetCurrentMethod.Name)
- End Try
- End Sub
- #End Region
I know that the SourceFile string and DestFile string need to ignore any and all CRs but I am not sure how to do it... I have tried adding a "str_SourceFile = trim.str_SourceFile to the local variables with no luck.
Thanks in advance for any help.