Dim thePath As String = "c:\karoasdksdkfnl\asklfdnkladf\file.txt" Dim theDir As String = Replace(thePath, thePath.Split("\")(thePath.Split("\").Count - 1), "")