C#DriveInfo的FileInfo [英] C# DriveInfo FileInfo

查看:152
本文介绍了C#DriveInfo的FileInfo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个愚蠢的问题,所以这里有云:



除了解析FileInfo.FullPath串的驱动器号,然后使用DriveInfo(C )等,以看是否有足够的空间来写该文件。有没有办法摆脱FileInfo的盘符?


解决方案

  FileInfo的F =新FileInfo的(路径); 
串驱动器= Path.GetPathRoot(f.FullName);

这将返回C:\。这真的是唯一的办法了。


This may seem like a stupid question, so here goes:

Other than parsing the string of FileInfo.FullPath for the drive letter to then use DriveInfo("c") etc to see if there is enough space to write this file. Is there a way to get the drive letter from FileInfo?

解决方案

FileInfo f = new FileInfo(path);    
string drive = Path.GetPathRoot(f.FullName);

This will return "C:\". That's really the only other way.

这篇关于C#DriveInfo的FileInfo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆