Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove the file name from the path returned by FileDialog.FileName?

How can I remove the actual file name from the path returned by the FileName property of an Open or Save File Dialog?

All I want is the path to the file without the file name.

like image 635
SpongeBob SquarePants Avatar asked Feb 04 '11 07:02

SpongeBob SquarePants


People also ask

How do I separate filenames from path?

To get the file name from the path, use the os. path. basename() method. Working with UNIX or MacOS uses the slash / as path separator, and Windows uses the backslash \ as the separator.

Does full path include filename?

Paths include the root, the filename, or both. That is, paths can be formed by adding either the root, filename, or both, to a directory.

What is filename with full path?

Hey guys, In this article, We will discuss how to get the filename from the full path in Linux. The full path means the address at which the file is located. This includes all the directories and subdirectories. For example, We have a file named file1. txt.


1 Answers

Pass the full path (the one including the file name) to the System.IO.Path.GetDirectoryName method. This will strip out the file name and return the full path to the directory containing that file.

For example:

Dim filePath As String = "C:\MyDir\MySubDir\myfile.ext"
Dim directoryPath As String = Path.GetDirectoryName(filePath)

Places the following string in the directoryPath variable:

C:\MyDir\MySubDir

like image 88
Cody Gray Avatar answered Oct 16 '22 04:10

Cody Gray