Get full path without filename from path that includes filename

前端 未结 6 1083
深忆病人
深忆病人 2020-12-12 21:27

Is there anything built into System.IO.Path that gives me just the filepath?

For example, if I have a string

@\"c:\

6条回答
  •  旧巷少年郎
    2020-12-12 22:02

        string fileAndPath = @"c:\webserver\public\myCompany\configs\promo.xml";
    
        string currentDirectory = Path.GetDirectoryName(fileAndPath);
    
        string fullPathOnly = Path.GetFullPath(currentDirectory);
    

    currentDirectory: c:\webserver\public\myCompany\configs

    fullPathOnly: c:\webserver\public\myCompany\configs

提交回复
热议问题