Visual Basic: Get the directory from a full file path

Platform:Visual Basic
Task:Get the directory from a full file path
Discussion:
You have a full file path but you just need the directory part (i.e. you need the 'C:\temp' part of 'C:\temp\file.txt'). Use the System.IO.FileInfo.
Example:
Dim TheFile As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo("C:\temp\file.txt")
Dim TheDirectory As String = TheFile.DirectoryName ' Get just the Directory segment of the pathname
Back to Index