detect CF card

  • Thread starter Thread starter cfyam
  • Start date Start date
-----Original Message-----
How can I detect CF card or SD card is exist in PDA Device?
I use a simple function using the Directory keyword
(probably smoother ways but this works. Written in C#:

using System;
using System.IO;

private void AssumeStorage()
{ // Tests for \Storage Card and \Flash File Store,
bool b = false;
b=Directory.Exists("\\Storage Card");
if (b)
// Handle existance of storage card"
else
b=Directory.Exists("\\Flash File Store");
if (b)
{
// Handle existance of Flash File Store"
}
else
{
// Handle no CF storage
}
}
 
You should be careful with assumptions... as each manufacturer will
determine what these 'defaults' will be. I have found it far more reliable
to present the user with a file dialog that asks them to point to file store
on their device. This provides the best results for all hardware, all
potential storage locations and is user proof...

Rick Winscot
www.zyche.com
 
As Rick said you should be aware that the name of the storage card may
change from device to device and from country to country.
What I've done is to use System.IO.Directory to read all the directories
contained on the root folder, and then P/Invoke: GetFileInformationByHandle
to see if the volume number is different from zero.

Hope this helps
Roberto
 
cfyam, you shouldn't check the existance of a certain directory.

I haven't tried it so far, but maybe you could use functions
FindFirstStore() and FindNextStore() to gather STORAGEDEVICEINFO structures
and check dwDeviceType field for STORAGE_DEVICE_TYPE_PCCARD and
STORAGE_DEVICE_TYPE_CFCARD ? Maybe this structure (or PARTINFO structure)
contains even a field which holds the mount point ...

Christian
 
Each device type can use different names for storage cards and they can also
be localised into numerous languages so this approach will only work on
specific devices.

A better approach (no P/Invokes required) is to enumerate all the top level
folders which have the Directory and Temporary. Alex Feinman produced a
useful code sample to do this here:-
http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=432

Peter
 
Back
Top