Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the drive letter from a path string or FileInfo

Tags:

c#

file-io

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?

like image 699
maxfridbe Avatar asked Dec 16 '08 01:12

maxfridbe


1 Answers

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

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

like image 62
BFree Avatar answered Oct 02 '22 16:10

BFree