Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

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.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

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

Navigation

Google Ads

VB.Net: Combining two strings to make a path

From Wiki

Jump to: navigation, search

for example you have a filename and a directory then do not just conactenate them but do Path.Combine.

  1. Imports System.IO
  2.  
  3. Module Module1
  4.  
  5.     Sub Main()
  6.         Dim _FileName1 As String = "filename.txt"
  7.         Dim _FileName2 As String = "temp\Command.com"
  8.         Dim _Path1 As String = "c:\"
  9.         Dim _Path2 As String = "c:\temp"
  10.         Console.WriteLine(Path.Combine(_Path1, _FileName1))
  11.         Console.WriteLine(Path.Combine(_Path1, _FileName2))
  12.         Console.WriteLine(Path.Combine(_Path2, _FileName1))
  13.         Console.WriteLine(Path.Combine(_Path2, _FileName2))
  14.         Console.ReadLine()
  15.     End Sub
  16.  
  17. 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).

515 Rating: 1.3/5 (3 votes cast)