Get Directory Name of a File Using VB.NET

In this article I describe how to get directory name of a file.
  • 3483

Get Directory Name of a File

The DirectoryName property returns the name of the directory of a file. The following code snippet returns the directory of a file.

Imports System.IO

Module Module1

    Sub Main()

        Dim fileName As String = "C:\Temp\MaheshTXFI.txt"

        Dim fi As New IO.FileInfo(fileName)

        Dim directoryName As String = fi.DirectoryName

        Console.WriteLine("Directory Name: {0}", directoryName)

        Console.ReadLine()

    End Sub

End Module

Output:

get directory name.jpg

Categories

More Articles

© 2018 DotNetHeaven. All rights reserved.