Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
VB.Net: Combining two strings to make a path
From Wiki
for example you have a filename and a directory then do not just conactenate them but do Path.Combine.
- Imports System.IO
- Module Module1
- Sub Main()
- Dim _FileName1 As String = "filename.txt"
- Dim _FileName2 As String = "temp\Command.com"
- Dim _Path1 As String = "c:\"
- Dim _Path2 As String = "c:\temp"
- Console.WriteLine(Path.Combine(_Path1, _FileName1))
- Console.WriteLine(Path.Combine(_Path1, _FileName2))
- Console.WriteLine(Path.Combine(_Path2, _FileName1))
- Console.WriteLine(Path.Combine(_Path2, _FileName2))
- Console.ReadLine()
- End Sub
- End Module
this will give you the following result
c:\filename.txt
c:\temp\command.com
c:\temp\filename.txt
c:\temp\temp\command.com
as you can see it will add the \ when neede and it will check if it is a valid path too before combining. It will not chech if the file exists (but that is easy enough).



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.