Getting the size (free, total) of a Windows Mobile phone drive using C#

前端 未结 2 636
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 02:37

How do I get the size (free, total) of any drive on a Windows Mobile phone using C#?

I need to do this with code running on the device (not on a connected PC).

2条回答
  •  野的像风
    2021-01-17 02:52

    Assuming the phone's drive is mounted as a regular volume in Windows (i.e., it has a drive letter in Windows Explorer), you can obtain this information using the System.IO.DriveInfo class.

    Next problem, of course, would be to determine which drive letter to use, as that will be different on just about every PC the phone is plugged into.

    A couple of options for that:

    • Scanning all available drives on the system for a special file that's guaranteed to be present on the phone. Environment.GetLogicalDrives will give you the list of all available drives on a system; some of these may be removable or otherwise inaccessible, though, which can cause some undesirable side-effects during your scan...
    • A more advanced approach would be to enumerate all available USB devices, and find your phone using its manufacturer/device ID. Although written for a slightly different purpose, this CodeProject article should point you in the right direction...

    And in case you want to run your code directly on the phone, and not on the PC it's attached to (your question doesn't elaborate on that...), this StackOverflow question shows how to obtain free space information on the Compact Framework.

    EDIT, in response to the elaboration that "when i use DriveInfo and give it the drive symbol it gives me the size of the local drive " My C: drive " not the C drive exists on the mobile": the C: drive of the phone will have a different drive letter (for example, F:) on the PC it's mounted on -- therefore the part of my answer that talks about finding the right drive letter. This does, of course, assume that your phone's drive is made available in its entirety on the host PC: depending on the phone model, this may or may not be the case. If not, running some code on your phone is the only viable solution for getting this information...

提交回复
热议问题