Home > Blockchain >  Get directory of filename
Get directory of filename

Time:10-18

So I am wondering how do I get the directory of a file.

So if I want to find the directory of C:\Directory\myfile.txt

I would get C:\Directory

How can I do this?

CodePudding user response:

You can use the Path.GetDirectoryName method

 var dirname = Path.GetDirectoryName(filename);

this will output C:\Directory

Don't forget to add the using System.IO

  •  Tags:  
  • c# io
  • Related