vb Code:
Private Sub SaveToText() Dim num As Integer Dim filenumber As Integer Dim s As Short Dim newstr(6) As String Dim I As Integer Dim Name As String Dim Label As String Dim AvailSpace As String Dim TSize As String Dim DriveFormat As String Dim DriveReady As String Dim ItemCount As Integer ItemCount = Me.ListView1.Items.Count If (Not System.IO.Directory.Exists("Drive Data")) Then System.IO.Directory.CreateDirectory("Drive Data") End If If File.Exists("DriveData\driveinfo" & num & ".txt") Then While File.Exists("DriveData\driveinfo" & num & ".txt") num = num + 1 End While filenumber = num Else filenumber = 1 End If Dim outputstream As New IO.StreamWriter("Drive Data\driveinfo" & filenumber & ".txt") For I = 0 To ItemCount - 1 For s = 0 To 5 newstr(s) = ListView1.Items.Item(I).SubItems(s).Text Next Name = newstr(0) Label = newstr(1) AvailSpace = newstr(2) TSize = newstr(3) DriveFormat = newstr(4) DriveReady = newstr(5) outputstream.WriteLine("Drive: " & Name.Trim() & " - " & Label.Trim() & " (Ready: " & DriveReady.Trim() & ")") outputstream.WriteLine("Available Space: " & AvailSpace.Trim()) outputstream.WriteLine("Total Capacity: " & TSize.Trim()) outputstream.WriteLine("Format: " & DriveFormat.Trim()) outputstream.WriteLine("") Next I outputstream.Close() MsgBox(filenumber) MsgBox("Export has been successfully created!", MsgBoxStyle.Information, "Information") 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.




Reply With Quote
