Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
With this function I get a random name, but is it possible to end these name's with the extension ".txt"?

Now it is for example ibnke0jb.dp3.
VB
Private Function GetTempFolder() As String
       Dim folder As String = Path.Combine(Path.GetTempPath, Path.GetRandomFileName)
       Do While Directory.Exists(folder) Or File.Exists(folder)
           folder = Path.Combine(Path.GetTempPath, Path.GetRandomFileName)
       Loop

       Return folder
   End Function
Posted
Updated 28-Mar-13 2:48am
v2

1 solution

Yes, return
VB
Path.ChangeExtension( folder, "txt")

This can be your modified code to do the file checking properly too-

VB
Private Function GetTempFolder() As String
        Dim folder As String =  Path.ChangeExtension(Path.Combine(Path.GetTempPath, Path.GetRandomFileName))
        Do While Directory.Exists(folder) Or File.Exists(folder)
            folder = Path.ChangeExtension(Path.Combine(Path.GetTempPath, Path.GetRandomFileName))
        Loop
 
        Return folder
    End Function


Though that repetition is really bugging me xD
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900