public static bool IsSameVolume(string path1, string path2) { try { var volInfo1 = new VolumeInfo(GetVolumePathName(path1), true, true); var volInfo2 = new VolumeInfo(GetVolumePathName(path2), true, true); return volInfo1.SerialNumber == volInfo2.SerialNumber; } catch { } return false; }
public DriveInfo(string driveName) { if (Utils.IsNullOrWhiteSpace(driveName)) throw new ArgumentNullException("driveName"); if (driveName.Length == 1) _name += Path.VolumeSeparatorChar; else _name = Path.GetPathRoot(driveName, false); if (Utils.IsNullOrWhiteSpace(_name)) throw new ArgumentException("Argument must be a drive letter (\"C\"), RootDir (\"C:\\\") or UNC path (\"\\\\server\\share\")"); // If an exception is thrown, the original drivePath is used. _name = Path.AddTrailingDirectorySeparator(_name, false); // Initiate VolumeInfo() lazyload instance. _volumeInfo = new VolumeInfo(_name, false, true); // Initiate DiskSpaceInfo() lazyload instance. _dsi = new DiskSpaceInfo(_name, null, false, true); }
public static string GetDriveFormat(string drivePath) { string fsName = new VolumeInfo(drivePath, true, true).FileSystemName; return Utils.IsNullOrWhiteSpace(fsName) ? null : fsName; }