title: Moving files into new folder using VB
body: <p>I have one Log file that keep a full path for *.docx extension every time it's created. The problem is I don't know how to split the file's name from the full path. Before move it, I can select which Path that have been created using CheckedListBox and move it to target folder.</p>
  
  <p>For example in my Log File I store (file has been created: <code>C:\Users\AsrahLim\Desktop\New Microsoft Word Document.docx</code>), all I need is the file's name "New Microsoft Word Document.docx" and move it to new folder .</p>
  
  <p>This is my target folder: <code>C:\Users\AsrahLim\Google Drive</code>. Below is my code.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Imports System.IO
  
  Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
          CheckedListBox1.Items.Add("Select/UnSelect All")
          CheckedListBox1.CheckOnClick = True
  
          Dim FILE_NAME As String = "C:\Users\AsrahLim\Desktop\LogFile.txt"
  
          If System.IO.File.Exists(FILE_NAME) Then
              Dim objReader As New System.IO.StreamReader(FILE_NAME)
              Do While objReader.Peek() &lt;&gt; -1
                  CheckedListBox1.Items.Add(objReader.ReadLine())
                  btnSave.Enabled = True
              Loop
          Else
              MessageBox.Show("File Does Not Exist")
              Close()
          End If
      End Sub
  
      Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
          If CheckedListBox1.CheckedItems.Count &lt;&gt; 0 Then
              For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
                  Dim SourcePath As String = CheckedListBox1.SelectedItem
                  Dim MoveLocation As String = "C:\Users\AsrahLim\Google Drive"
                  SourcePath = SourcePath.Substring(SourcePath.LastIndexOf("- ") + 1)
  
                  If File.Exists(SourcePath) = True Then
                      File.Move(SourcePath, MoveLocation)
                      MsgBox("File Moved")
                  Else
                      MsgBox("File Not move")
                  End If
              Next
          End If
      End Sub
  
      Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
          Close()
      End Sub
  End Class
  </code></pre>