Extract file name from full path?

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

Is there a method that will take a full path and filename as a
parameter and return just the filename? I am currently using the
following code but it is extremely slow for files on a DVD.

for (int I = 0; I < openVobDialog.FileNames.Length; I++)
{
FileInfo vobInfo = new FileInfo(openVobDialog.FileNames);
vobListBox.Items.Add(vobInfo.Name);
}
 
Hi there... you can use the System.IO.Path.GetFileName() method. For
example:

String myfullpath = @"c:\Folder1\SubFolder\MyFile.txt";
MessageBox.Show(System.IO.Path.GetFileName(myfullpath)); // Shows MyFile.txt

Regards,
 
Back
Top