How to: List and Locate Storage Card Files

Send Feedback

The examples in this topic demonstrate how to list and locate storage card files.

The SHGetDocumentsFolder function works with storage cards that do not have a My Documents folder as well as with older storage cards that do. You should use SHGetDocumentsFolder when accessing all documents on the device, whether they are in main memory or on a storage card.

Example

#include <shlobj.h>

TCHAR szPath[MAX_PATH];
if (! SHGetDocumentsFolder(_T("\\"), szPath))
  {
  MessageBox(NULL, _T("Invalid Path"), _T("Call Failed"), MB_OK);
  }
else
  {
  MessageBox(NULL, szPath, _T("My Docs Path"), MB_OK);
  }

You can also use the EnumProjectsEx and EnumProjectsFilesEx functions to list all folders and files on your storage cards and then use FindFirstProjectFile and FindNextProjectFile to locate particular files, as shown in the following example.

Example

#include <shlobj.h>
int iNumFolders;
TCHAR szName[1000];
TCHAR cFileName[1000];
int iNumOfFlashCard = 1;

for (int index = 0; index < iNumOfFlashCard; ++index)
{
  // Store the directory name in szName.
  wsprintf(szName, lpwfdFlashCard[index].cFileName); 
  iNumFolders = EnumProjects (EnumProjProc, lpwfdFlashCard[index].dwOID, PRJ_ENUM_FLASH, 0);
}

  // Note: In the preceding code, EnumProjProc is a user-defined 
  // callback function that is used to perform operations within each 
  // directory that EnumProjects encounters. 
  // The following code shows how to use EnumProjProc to find 
  // directories and files on storage cards.
BOOL CALLBACK EnumProjProc (DWORD dwOID, LPARAM lParam)
{
  // Search handle for files under each directory. 
  HANDLE hSearch;    
  // Structure for storing the storage card information 
  // retrieved by CeOidGetInfo.
  CEOIDINFO OidInfo; 
  // Structure for storing file information.
  WIN32_FIND_DATA fd; 
  // String for storing the file or directory 
  // name on every storage card.
  TCHAR szName[1000]; 
  // String for storing the error message.
  TCHAR szErrorMsg[1000];    
  // Wildcard file names with full paths for searching these 
  // types of files.
  TCHAR szFilePath[MAX_PATH]; 
  // Whether the search for files is finished.
  BOOLEAN bFinished = FALSE; 

  // Get storage card information by using its object identifier.
  CeOidGetInfo(dwOID, &OidInfo);
  // Store the directory name in szName.
  wsprintf(szName, OidInfo.infDirectory.szDirName); 
  // Construct the wildcard file name with the full path for searching 
  // that type of file.
  wcscpy(szFilePath, OidInfo.infDirectory.szDirName);
  wcscat(szFilePath, TEXT("\\*.*"));
  // Search for the first project file under the current directory.
  hSearch = FindFirstProjectFile( szFilePath, &fd);
  if (hSearch == INVALID_HANDLE_VALUE) 
    { 
    wsprintf(szErrorMsg, TEXT("No files found.")); 
    bFinished = TRUE;      
    }

  // Find all of the files and retrieve the file names.
  while (!bFinished) 
    { 
    // Store the file name in szName.
    wsprintf(szName, fd.cFileName); 
    if (!FindNextProjectFile(hSearch, &fd)) 
      {
      // Finished.
      bFinished = TRUE;
      if (GetLastError() == ERROR_NO_MORE_FILES) 
        { 
        wsprintf(szErrorMsg, TEXT("Found all of the files.")); 
        } 
      }
    } 

  // Close the search handle. 
  FindClose(hSearch);
  return TRUE;
}

See Also

File and Application Management Reference | How to: Enumerate Storage Cards

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.