4

How can I find the physical drive a file/directory is located on. I want to compare 2 files and if they are on two separate drives, then I can speed up the compare by reading both simultaneously.

Regards

jdphenix
  • 15,022
  • 3
  • 41
  • 74
Peter
  • 1,685
  • 3
  • 16
  • 22
  • 2
    i would read both simultaneously anyway, especially if its C# – n00b Mar 05 '11 at 23:57
  • @n00b Reading simultaneously in multiple locations on a hard-disk can slow the reading down significantly due to the high seek times a normal hard-disk has. – CodesInChaos Mar 05 '11 at 23:59
  • @CodeInChaos: depends on the disk. If its on a RAID array for instance... – Mitch Wheat Mar 06 '11 at 00:00
  • But due to symlinks and junctions you can't really do it per drive letter. And SSDs have different performance characteristics too where most likely reading parallel isn't slower than reading sequentially. – CodesInChaos Mar 06 '11 at 00:01
  • @CodeInChaos what Mitch said and well since its really not that big of a performance loss and the drives get faster and faster and c#(.NET) gets slower and slower i dont see that as a problem ;P but you could use a size threshold (if file – n00b Mar 06 '11 at 00:03

2 Answers2

3

This may require P/Invoke.

Way to know if two partitions are in one physical hard disk without WMI?

From above link:

The Win32 function you'll need is called DeviceIoControl(). The API documentation can be found at http://msdn.microsoft.com/en-us/library/aa363216(VS.85).aspx. Call DeviceIoControl() with the control code IOCTL_STORAGE_GET_DEVICE_NUMBER and you'll get the physical disk drive for the given partition device handle. The device handle for the partition can be retrieved using CreateFile() API.

Community
  • 1
  • 1
Justin Skiles
  • 9,373
  • 6
  • 50
  • 61
3

Read both simultaneously regardless.

At worst it might be slightly slower (depends on the actual physical disk(s)).

At best it will be faster.

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541