Question : Visual Studio VB

Hi

i'm using the following code to delete Files and Folders From a Test folder called Test2 under my Desktop.

How can i use a virable like: "%userprofile%\Desktop\Test2" instead of Admin (my username)
Br
ms-pro
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
ublic Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As String


        For Each s In System.IO.Directory.GetFiles("C:\Users\Admin\Desktop\Test2\")
            System.IO.File.Delete(s)
        Next s


        For Each s In System.IO.Directory.GetDirectories("C:\Users\Admin\Desktop\Test2\")
            System.IO.Directory.Delete(s)
        Next s
    End Sub
End Class

Answer : Visual Studio VB

I think this is the idea.

~bp
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Public Class Form1
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim s As String
        Dim up As String
 
        up = Environment.GetEnvironmentVariable("userprofile")
 
        For Each s In System.IO.Directory.GetFiles(up & "\Desktop\Test2\")
            System.IO.File.Delete(s)
        Next s
 
        For Each s In System.IO.Directory.GetDirectories(up & "\Desktop\Test2\")
            System.IO.Directory.Delete(s)
        Next s
    End Sub
End Class
Random Solutions  
 
programming4us programming4us