Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get only the file name without the File Path?

Tags:

c#

winforms

i have this code:

openFileDialog1.Filter = "csv files (*.dbf)|*.dbf";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
openFileDialog1.FileName = "";

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
   dbf_File = openFileDialog1.FileName;
}

in dbf_File i get all the file path and name (c:\MyDir\MyFile.dbf)

i need only the name - MyFile.dbf

like image 569
Gali Avatar asked Oct 05 '11 09:10

Gali


People also ask

How do I separate the filename and path?

To extract filename from the file, we use “GetFileName()” method of “Path” class. This method is used to get the file name and extension of the specified path string. The returned value is null if the file path is null.

How do I get only the ls filename?

If you want the ls command output to only contain file/directory names and their respective sizes, then you can do that using the -h option in combination with -l/-s command line option.

How do I get only the filename in Linux?

If you want to display only the filename, you can use basename command. find infa/bdm/server/source/path -type f -iname "source_fname_*. txt" Shell command to find the latest file name in the command task!


Video Answer


1 Answers

Only the file name (with extension):

dbf_File = System.IO.Path.GetFileName(dbf_File);

Only the containing directory:

string dbf_Path = System.IO.Path.GetDirectoryName(dbf_File);
like image 65
Ishmaeel Avatar answered Oct 12 '22 05:10

Ishmaeel