vb Code:
  1. Private Sub SaveToText()
  2.  
  3.         Dim num As Integer
  4.         Dim filenumber As Integer
  5.  
  6.         Dim s As Short
  7.         Dim newstr(6) As String
  8.  
  9.         Dim I As Integer
  10.  
  11.         Dim Name As String
  12.         Dim Label As String
  13.         Dim AvailSpace As String
  14.         Dim TSize As String
  15.         Dim DriveFormat As String
  16.         Dim DriveReady As String
  17.  
  18.         Dim ItemCount As Integer
  19.         ItemCount = Me.ListView1.Items.Count
  20.  
  21.         If (Not System.IO.Directory.Exists("Drive Data")) Then
  22.             System.IO.Directory.CreateDirectory("Drive Data")
  23.         End If
  24.  
  25.         If File.Exists("DriveData\driveinfo" & num & ".txt") Then
  26.             While File.Exists("DriveData\driveinfo" & num & ".txt")
  27.                 num = num + 1
  28.             End While
  29.             filenumber = num
  30.         Else
  31.             filenumber = 1
  32.         End If
  33.  
  34.         Dim outputstream As New IO.StreamWriter("Drive Data\driveinfo" & filenumber & ".txt")
  35.  
  36.         For I = 0 To ItemCount - 1
  37.  
  38.             For s = 0 To 5
  39.                 newstr(s) = ListView1.Items.Item(I).SubItems(s).Text
  40.             Next
  41.  
  42.             Name = newstr(0)
  43.             Label = newstr(1)
  44.             AvailSpace = newstr(2)
  45.             TSize = newstr(3)
  46.             DriveFormat = newstr(4)
  47.             DriveReady = newstr(5)
  48.  
  49.             outputstream.WriteLine("Drive: " & Name.Trim() & " - " & Label.Trim() & " (Ready: " & DriveReady.Trim() & ")")
  50.             outputstream.WriteLine("Available Space: " & AvailSpace.Trim())
  51.             outputstream.WriteLine("Total Capacity: " & TSize.Trim())
  52.             outputstream.WriteLine("Format: " & DriveFormat.Trim())
  53.             outputstream.WriteLine("")
  54.  
  55.         Next I
  56.  
  57.         outputstream.Close()
  58.  
  59.         MsgBox(filenumber)
  60.         MsgBox("Export has been successfully created!", MsgBoxStyle.Information, "Information")
  61.  
  62.     End Sub

Here's my code, and I can get it to create the directory "Drive Data" if it doesn't exist, and a file gets created as "driveinfo1.txt" but if that file exists it won't save the new file as "driveinfo2.txt" which is what i'm trying to get this code to do.

If anyone can help me understand where the logic in this is wrong and put me on the right path i'd appreciate that. Don't need someone to write the code for me, but i'm sure i'm just doing some silly mistake in this code not allowing it to work the way I want it to.