<p>Is there an easy way to find the storage card's path on a Windows Mobile device
when there is a storage card and a bluetooth ftp connection?</p>

[{'answer_id': 41316, 'author': 'Dominik Grabiec', 'author_id': 3719, 'author_profile': 'https://Stackoverflow.com/users/3719', 'pm_score': 1, 'selected': False, 'text': '<p>On Windows CE 5 (which is the base for Windows Mobile 6) the storage cards get mounted at the root file system as "Storage Card\\", "Storage Card2\\", etc.</p>\n\n<p>To find out if it\'s mounted call GetFileAttributes (or the remote version CeGetFileAttributes I believe) passing in the full path ("\\Storage Card\\"). If it returns INVALID_FILE_ATTRIBUTES then it\'s not mounted, otherwise check to make sure it\'s a directory before returning true.</p>\n'}, {'answer_id': 48430, 'author': 'Tim Norman', 'author_id': 2716, 'author_profile': 'https://Stackoverflow.com/users/2716', 'pm_score': 3, 'selected': False, 'text': '<p>The mount point is usually "\\Storage Card" but can be localized into other languages or modified by OEMs (some devices use "\\SD Card" or other mount points, and some devices support mounting multiple storage media).  The best way to enumerate the available cards is to use FindFirstFlashCard and FindNextFlashCard.</p>\n\n<p>Both functions fill in a WIN32_FIND_DATA structure.  The most important field is cFileName, which will contain the path to the card\'s mount point (e.g. "\\Storage Card").</p>\n\n<p>Note that the device\'s internal memory will also be enumerated by these functions.  If you only care about external volumes, ignore the case where cFileName is an empty string ("").</p>\n\n<p>Using these functions require you to #include &lt;projects.h&gt; and link with note_prj.lib.  Both are included in the Windows Mobile SDKs for WM 2000 and later.</p>\n'}, {'answer_id': 661129, 'author': 'Joel ', 'author_id': 79853, 'author_profile': 'https://Stackoverflow.com/users/79853', 'pm_score': 4, 'selected': True, 'text': '<p>Keep in mind that "\\Storage Card" is english oriented.  A device made for a different region may have a different name.  The name of the storage card path on my device varies with how I am using the device. </p>\n\n<p>Some time ago in the MSDN forms I responded to a few questions on how to detect the storage cards in the file system and how does one get the storage card\'s capacity. I wrote the following could are a response to those questions and thought it would be helpful to share.  Storage cards show up in the file system as temporary directories.  This program examines the objects in the root of the device and any folders that have temp attribute are considered to be a positive match </p>\n\n<pre><code>using System;\nusing System.IO;\nusing System.Runtime.InteropServices;\n\nnamespace StorageCardInfo\n{\n    class Program\n    {\n        const ulong Megabyte = 1048576;\n        const ulong Gigabyte = 1073741824;\n\n        [DllImport("CoreDLL")]\n        static extern int GetDiskFreeSpaceEx(\n        string DirectoryName,\n        out ulong lpFreeBytesAvailableToCaller,\n        out ulong lpTotalNumberOfBytes,\n        out ulong lpTotalNumberOfFreeBytes \n    );\n\n    static void Main(string[] args)\n    {\n        DirectoryInfo root = new DirectoryInfo("\\\\");\n        DirectoryInfo[] directoryList = root.GetDirectories();\n        ulong FreeBytesAvailable;\n        ulong TotalCapacity;\n        ulong TotalFreeBytes;\n\n        for (int i = 0; i &lt; directoryList.Length; ++i)\n        {\n            if ((directoryList.Attributes &amp; FileAttributes.Temporary) != 0)\n            {\n                GetDiskFreeSpaceEx(directoryList.FullName, out FreeBytesAvailable, out TotalCapacity, out TotalFreeBytes);\n                Console.Out.WriteLine("Storage card name: {0}", directoryList.FullName);\n                Console.Out.WriteLine("Available Bytes : {0}", FreeBytesAvailable);\n                Console.Out.WriteLine("Total Capacity : {0}", TotalCapacity);\n                Console.Out.WriteLine("Total Free Bytes : {0}", TotalFreeBytes);\n            }\n        }\n    }\n}\n</code></pre>\n'}, {'answer_id': 698076, 'author': 'John Sibly', 'author_id': 1078, 'author_profile': 'https://Stackoverflow.com/users/1078', 'pm_score': 3, 'selected': False, 'text': '<p>I\'ve found using the FindFirstFlashCard/FindNextFlashCard APIs to be more reliable than enumerating directories and checking the temporary flag (which will return bluetooth shared folders for example). </p>\n\n<p>The following sample application demonstrates how to use them and the required P/Invoke statements.</p>\n\n<pre><code>using System;\nusing System.Runtime.InteropServices;\n\nnamespace RemovableStorageTest\n{\n    class Program\n    {\n        static void Main(string[] args)\n        {\n            string removableDirectory = GetRemovableStorageDirectory();\n            if (removableDirectory != null)\n            {\n                Console.WriteLine(removableDirectory);\n            }\n            else\n            {\n                Console.WriteLine("No removable drive found");\n            }\n        }\n\n        public static string GetRemovableStorageDirectory()\n        {\n            string removableStorageDirectory = null;\n\n            WIN32_FIND_DATA findData = new WIN32_FIND_DATA();\n            IntPtr handle = IntPtr.Zero;\n\n            handle = FindFirstFlashCard(ref findData);\n\n            if (handle != INVALID_HANDLE_VALUE)\n            {\n                do\n                {\n                    if (!string.IsNullOrEmpty(findData.cFileName))\n                    {\n                        removableStorageDirectory = findData.cFileName;\n                        break;\n                    }\n                }\n                while (FindNextFlashCard(handle, ref findData));\n                FindClose(handle);\n            }\n\n            return removableStorageDirectory;\n        }\n\n        public static readonly IntPtr INVALID_HANDLE_VALUE = (IntPtr)(-1);\n\n        // The CharSet must match the CharSet of the corresponding PInvoke signature\n        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]\n        public struct WIN32_FIND_DATA\n        {\n            public int dwFileAttributes;\n            public FILETIME ftCreationTime;\n            public FILETIME ftLastAccessTime;\n            public FILETIME ftLastWriteTime;\n            public int nFileSizeHigh;\n            public int nFileSizeLow;\n            public int dwOID;\n            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]\n            public string cFileName;\n            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]\n            public string cAlternateFileName;\n        }\n\n        [StructLayout(LayoutKind.Sequential)]\n        public struct FILETIME\n        {\n            public int dwLowDateTime;\n            public int dwHighDateTime;\n        };\n\n        [DllImport("note_prj", EntryPoint = "FindFirstFlashCard")]\n        public extern static IntPtr FindFirstFlashCard(ref WIN32_FIND_DATA findData);\n\n        [DllImport("note_prj", EntryPoint = "FindNextFlashCard")]\n        [return: MarshalAs(UnmanagedType.Bool)]\n        public extern static bool FindNextFlashCard(IntPtr hFlashCard, ref WIN32_FIND_DATA findData);\n\n        [DllImport("coredll")]\n        public static extern bool FindClose(IntPtr hFindFile);\n    }\n}\n</code></pre>\n'}, {'answer_id': 840425, 'author': 'Tristan Warner-Smith', 'author_id': 29553, 'author_profile': 'https://Stackoverflow.com/users/29553', 'pm_score': 2, 'selected': False, 'text': '<p>There\'s a pure C# way to do this without native calls.</p>\n\n<p>Taken from <a href="http://www.treehouseconsulting.co.uk/Blog/post/2009/05/08/Accessing-the-memory-card-in-Windows-Mobile.aspx" rel="nofollow noreferrer">here</a>.</p>\n\n<pre><code>//codesnippet:06EE3DE0-D469-44DD-A15F-D8AF629E4E03\npublic string GetStorageCardFolder()\n{\n   string storageCardFolder = string.Empty;\n   foreach (string directory in Directory.GetDirectories("\\\\"))\n   {\n       DirectoryInfo dirInfo = new DirectoryInfo(directory);\n\n       //Storage cards have temporary attributes do a bitwise check.\n        //http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=612136&amp;SiteID=1\n        if ((dirInfo.Attributes &amp; FileAttributes.Temporary) == FileAttributes.Temporary)\n            storageCardFolder = directory;\n    }\n\n    return storageCardFolder;\n}\n</code></pre>\n'}, {'answer_id': 2027247, 'author': 'lmb_nl', 'author_id': 246350, 'author_profile': 'https://Stackoverflow.com/users/246350', 'pm_score': 2, 'selected': False, 'text': '<p>Can\'t add a comment on the TreeUK and ctacke discusion below : </p>\n\n<blockquote>\n  <p>This isn\'t guaranteed to find a\n  Storage Card - many devices mount\n  built-in flash in teh same way, and it\n  would show up in this list as well. –\n  ctacke May 8 at 18:23<br>\n  This has\n  worked well for me on HTC and Psion\n  devices. What devices are you aware\n  this doesn\'t work on? Would be worth\n  seeing if there\'s another attribute\n  you can discount the build in flash\n  memory with. – TreeUK May 9 at 22:29</p>\n</blockquote>\n\n<p>To give a idea on a Motorola MC75 (used to be SymboL), i used this piece (of native) code : </p>\n\n<pre><code>    WIN32_FIND_DATA cardinfo;\nHANDLE  card = FindFirstFlashCard(&amp;cardinfo);\nif (card != INVALID_HANDLE_VALUE)\n{\n    TCHAR existFile[MAX_PATH];\n\n    wprintf(_T("found : %s\\n"), cardinfo.cFileName);\n\n    while(FindNextFlashCard(card, &amp;cardinfo))\n    {\n        wprintf(_T("found : %s\\n"), cardinfo.cFileName);\n    }\n}\nFindClose(card);\n</code></pre>\n\n<p>Debug output : </p>\n\n<pre><code>cardinfo.dwFileAttributes   0x00000110  unsigned long int\ncardinfo.cFileName          "Application"   wchar_t[260]\n\ncardinfo.dwFileAttributes   0x00000110  unsigned long int\ncardinfo.cFileName          "Cache Disk"    wchar_t[260]\n\ncardinfo.dwFileAttributes   0x00000110  unsigned long int\ncardinfo.cFileName          "Storage Card"  wchar_t[260]\n</code></pre>\n\n<p>The "Application" and "Cache disk" are internal Flash drives. The "Storage Card" a removable SD Card. All are marked as a FlashDrive (which they are), but only "Storage Card" is removable. </p>\n'}, {'answer_id': 7272591, 'author': 'qwlice', 'author_id': 507127, 'author_profile': 'https://Stackoverflow.com/users/507127', 'pm_score': 2, 'selected': False, 'text': '<p>I post here the code that I use to get the mount dirs of the storage cards.\nThe part where I get the flash cards paths is copied from Sibly\'s post with a few changes.</p>\n\n<p>The main difference is in that I search through the mount dirs of all the flash cards and I keep the one(s) that match the default storage card name that I read from windows\' registry.</p>\n\n<p>It solves the problem that one has on motorola\'s smart devices where there are multiple flash cards and only one sd card reader whose mount dir\'s name can change from the default by the numeric suffix (ie. in english WM systems: \'Storage Card\' , \'Storage Card2\' and so on). \nI tested it on some motorola models (MC75, MC75A, MC90, MC65) with WM 6.5 english. </p>\n\n<p>This solution should work well with different windows mobile\'s languages but I don\'t know if it can deal with those that change the\ndefault name of the storage cards.\nIt all depends whether the device\'s manufacturer updates the windows registry with the <strong>new</strong> default name.</p>\n\n<p>It would be great if you can test it on different WMs or devices.\nFeedback is welcome.</p>\n\n<pre class="lang-cs prettyprint-override"><code>   //\n   // the storage card is a flash drive mounted as a directory in the root folder \n   // of the smart device\n   //\n   // on english windows mobile systems the storage card is mounted in the directory "/Storage Card", \n   // if that directory already exists then it\'s mounted in "/Storage Card2" and so on\n   //\n   // the regional name of the mount base dir of the storage card can be found in\n   // the registry at [HKEY_LOCAL_MACHINE\\System\\StorageManager\\Profiles\\SDMemory\\Folder]\n   //  \n   // in order to find the path of the storage card we look for the flash drive that starts \n   // with the base name\n   //\n\n   public class StorageCard\n   {\n      private StorageCard()\n      {\n      }\n\n      public static List&lt;string&gt; GetMountDirs()\n      {\n         string key = @"HKEY_LOCAL_MACHINE\\System\\StorageManager\\Profiles\\SDMemory";\n         string storageCardBaseName = Registry.GetValue(key, "Folder", "Storage Card") as String;\n         List&lt;string&gt; storageCards = new List&lt;string&gt;();\n         foreach (string flashCard in GetFlashCardMountDirs())\n         {\n            string path = flashCard.Trim();\n            if (path.StartsWith(storageCardBaseName))\n            {\n               storageCards.Add(path);\n            }\n         }\n         return storageCards;\n      }\n\n      private static List&lt;string&gt; GetFlashCardMountDirs()\n      {\n         List&lt;string&gt; storages = new List&lt;string&gt;();\n\n         WIN32_FIND_DATA findData = new WIN32_FIND_DATA();\n         IntPtr handle = IntPtr.Zero;\n\n         handle = FindFirstFlashCard(ref findData);\n\n         if (handle != INVALID_HANDLE_VALUE)\n         {\n            do\n            {\n               if (!string.IsNullOrEmpty(findData.cFileName))\n               {\n                  storages.Add(findData.cFileName);\n                  storages.Add(findData.cAlternateFileName);\n               }\n            }\n            while (FindNextFlashCard(handle, ref findData));\n            FindClose(handle);\n         }\n\n         return storages;\n      }\n\n      private static readonly IntPtr INVALID_HANDLE_VALUE = (IntPtr)(-1);    \n\n      [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]\n      private struct WIN32_FIND_DATA\n      {\n         public int dwFileAttributes;\n         public FILETIME ftCreationTime;\n         public FILETIME ftLastAccessTime;\n         public FILETIME ftLastWriteTime;\n         public int nFileSizeHigh;\n         public int nFileSizeLow;\n         public int dwOID;\n         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]\n         public string cFileName;\n         [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)]\n         public string cAlternateFileName;\n      }\n\n      [StructLayout(LayoutKind.Sequential)]\n      private struct FILETIME\n      {\n         public int dwLowDateTime;\n         public int dwHighDateTime;\n      };\n\n      [DllImport("note_prj", EntryPoint = "FindFirstFlashCard")]\n      private extern static IntPtr FindFirstFlashCard(ref WIN32_FIND_DATA findData);\n\n      [DllImport("note_prj", EntryPoint = "FindNextFlashCard")]\n      [return: MarshalAs(UnmanagedType.Bool)]\n      private extern static bool FindNextFlashCard(IntPtr hFlashCard, ref WIN32_FIND_DATA findData);\n\n      [DllImport("coredll")]\n      private static extern bool FindClose(IntPtr hFindFile);\n   }\n</code></pre>\n'}, {'answer_id': 12400572, 'author': 'Lief', 'author_id': 778579, 'author_profile': 'https://Stackoverflow.com/users/778579', 'pm_score': 2, 'selected': False, 'text': '<p>I have combined a number of the solutions above, particularly qwlice\'s code, to find SD cards on a range of devices. This solution finds SD cards only (so excludes all of the internal "storage cards" that some devices have) without using native dll calls.</p>\n\n<p>The code searches the HKEY_LOCAL_MACHINE\\System\\StorageManager\\Profiles\\ key for keys containing "SD" as the name varies slightly on some devices, finds the default mount dir and then looks for temp directories that start with this. This means that it will find \\StorageCard2, \\StorageCard3, etc. </p>\n\n<p>I have been using this on a range of Intermec and Motorola/Symbol devices and haven\'t had any problems. Here is the code below:</p>\n\n<pre class="lang-cs prettyprint-override"><code>public class StorageCardFinder\n{\n    public static List&lt;string&gt; GetMountDirs()\n    {\n        //get default sd card folder name\n        string key = @"HKEY_LOCAL_MACHINE\\System\\StorageManager\\Profiles";\n        RegistryKey profiles = Registry.LocalMachine.OpenSubKey(@"System\\StorageManager\\Profiles");\n        string sdprofilename = profiles.GetSubKeyNames().FirstOrDefault(k =&gt; k.Contains("SD"));\n        if (sdprofilename == null)\n            return new List&lt;string&gt;();\n\n        key += "\\\\" + sdprofilename;\n        string storageCardBaseName = Registry.GetValue(key, "Folder", "Storage Card") as String;\n        if (storageCardBaseName == null)\n            return new List&lt;string&gt;();\n\n        //find storage card\n        List&lt;string&gt; cardDirectories = GetFlashCardMountDirs();\n\n        List&lt;string&gt; storageCards = new List&lt;string&gt;();\n        foreach (string flashCard in GetFlashCardMountDirs())\n        {\n            string path = flashCard.Trim();\n            if (path.StartsWith(storageCardBaseName))\n            {\n                storageCards.Add("\\\\" + path);\n            }\n        }\n        return storageCards;\n    }\n\n    private static List&lt;string&gt; GetFlashCardMountDirs()\n    {\n        DirectoryInfo root = new DirectoryInfo("\\\\");\n        return root.GetDirectories().Where(d =&gt; (d.Attributes &amp; FileAttributes.Temporary) != 0)\n                                    .Select(d =&gt; d.Name).ToList();\n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/40269', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4298/']