Download the source code

This part of the Using RAPI series explains how to enumerate files and folders of the connected device. In previous part I explained how to enumerate database on the connected device.

After creating the IRAPISession using the CreateSession, we can use the CeFindFirstFile and CeFindNextFile to enumerate all the files and folders. This will return the file information in CE_FIND_DATA structure. The CE_FIND_DATA is defined as:

typedef struct CE_FIND_DATA
    DWORD    dwFileAttributes;
    FILETIME ftCreationTime;
    FILETIME ftLastAccessTime;
    FILETIME ftLastWriteTime;
    DWORD    nFileSizeHigh;
    DWORD    nFileSizeLow;
    DWORD    dwOID;
    WCHAR    cFileName[MAX_PATH];

The CeFindFirstFile’s first parameter is file pattern and second parameter is a pointer to CE_FIND_DATA structure which receives the information about the file. The function returns a find handle. The CeFindNextFile’s first parameter is the handle returned by the CeFindFirstFile and second parameter is a pointer to the CE_FIND_DATA structure. The function returns TRUE is a file is found otherwise FALSE.

The sample application presented here is a regular MFC application which lists all the folders in left pane and files in right pane. The application is created using Visual Studio 2008.