[Mono-dev] Help needed with UnixDriveInfo

2006-05-24 Thread Arnhoffer Károly
Hi,

I would like to try UnixDriveInfo but I can not know how to start. As I can see 
to construct a UnixDriveInfo object I have to give a mount point. How can I get 
the mount point part of a path? 

For example I have a different partition (and different mount points) for / and 
an other for /home but my application may not know anything about it. My 
application gets the path /home/pulcsi/Documents and it has to deceide what the 
mount point here is to give it to UnixDriveInfo constructor. How should it do 
it?

Thaks!

Károly
___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list


Re: [Mono-dev] Help needed with UnixDriveInfo

2006-05-24 Thread Jonathan Pryor
On Wed, 2006-05-24 at 10:56 +0200, Arnhoffer Károly wrote:
 I would like to try UnixDriveInfo but I can not know how to start. As
 I can see to construct a UnixDriveInfo object I have to give a mount
 point. How can I get the mount point part of a path? 

In general, you don't, since a mount point can be anywhere...

 For example I have a different partition (and different mount points)
 for / and an other for /home but my application may not know anything
 about it. My application gets the path /home/pulcsi/Documents and it
 has to deceide what the mount point here is to give it to
 UnixDriveInfo constructor. How should it do it?

Use UnixDriveInfo.GetDrives() to get all known mount points, then use
UnixDriveInfo.Name to determine which drive best corresponds to your
path:

using System;
using Mono.Unix;

class Test {
  public static void Main (string[] paths)
  {
UnixDriveInfo[] drives = UnixDriveInfo.GetDrives ();

foreach (string path in paths) {
  int idx = -1, count = -1;
  for (int i = 0; i  drives.Length; ++i) {
if (path.StartsWith (drives [i].Name) 
  drives [i].Name.Length  count) {
  count = drives [i].Name.Length;
  idx = i;
}
  }
  Console.WriteLine (Drive for `{0}' is {1} (device {2}),
path, drives [idx].Name, drives [idx].VolumeLabel);
}
  }
}

 - Jon


___
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list