ExtractFilePath() ?

  • Thread starter Thread starter Kostya Ergin
  • Start date Start date
K

Kostya Ergin

Hi!

I have a path to a file: "C:\dir\file.txt"

How to get directory path? ("C:\dir\")

In Delphi there was a function ExtractFilePath(path). I searched in MSDN and
have not found. Somebody knows?
 
Excuse, I have guessed independently :)

string path = Path.GetDirectoryName(FilePath);
 
In Delphi there was a function ExtractFilePath(path). I searched in MSDN and
have not found. Somebody knows?

It seems that I as a Delphi programmer am not the only one struggling
with these kind of questions. I would love to read the book "C# for
Delphi developers", wouldn't you?


GetDirectoryName Returns the directory information for the specified
path string.

string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string rootPath = @"C:\";
string directoryName;

directoryName = Path.GetDirectoryName(fileName);
Console.WriteLine("GetDirectoryName('{0}') returns '{1}'",
fileName, directoryName);

directoryName = Path.GetDirectoryName(path);
Console.WriteLine("GetDirectoryName('{0}') returns '{1}'",
path, directoryName);

directoryName = Path.GetDirectoryName(rootPath);
Console.WriteLine("GetDirectoryName('{0}') returns '{1}'",
rootPath, directoryName);



Cheers,

chris
 
Back
Top