⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdir.c

📁 SMART PHONE 2005中关于RAPI的源码
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*****************************************************************************

  PROGRAM: pdblist.c

  ABSTRACT:
    This sample lists all the files in a certain directory.

******************************************************************************/
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <string.h>
#include <rapi.h>
#include <strsafe.h>

#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))

WCHAR wszDirectory[MAX_PATH];

TCHAR *tszMonths[12] = {TEXT("Jan"),
                        TEXT("Feb"),
                        TEXT("Mar"),
                        TEXT("Apr"),
                        TEXT("May"),
                        TEXT("Jun"),
                        TEXT("Jul"),
                        TEXT("Aug"),
                        TEXT("Sep"),
                        TEXT("Oct"),
                        TEXT("Nov"),
                        TEXT("Dec")};

int main( int argc, char *argv[])
{
    HANDLE hFind;
    WORD wFatTime, wFatDate;
    CE_FIND_DATA wfd;
    HRESULT hRapiResult;
    HRESULT hr;
    int     nResult;

    if (2 != argc)
    {
        hr = StringCchCopyW(wszDirectory, ARRAYSIZE(wszDirectory),  L"\\*");
        if(FAILED(hr))
        {
            return 1;
        }
    }
    else
    {
#ifdef UNICODE
        nResult = MultiByteToWideChar(
                                      CP_ACP,    
                                      MB_PRECOMPOSED,
                                      argv[1],
                                      strlen(argv[1])+1,
                                      wszDirectory,
                                      ARRAYSIZE(wszDirectory));
        if(0 == nResult)
        {
            _tprintf(TEXT("Failed to convert input arguement\n"));
            return 1;
        }
#else
        hr = StringCchCopy(wszDirectory, ARRAYSIZE(wszDirectory), argv[1]);
        if(FAILED(hr))
        {
            return 1;
        }
#endif
    }

    _tprintf( TEXT("Connecting to Windows CE..."));
    
    hRapiResult = CeRapiInit();

    if (FAILED(hRapiResult))
    {
        _tprintf( TEXT("Failed\n"));
        return 1;
    }

    _tprintf( TEXT("Success\n"));

    _tprintf( wszDirectory);
        
    _tprintf( TEXT("\n"));

    hFind = CeFindFirstFile( wszDirectory, &wfd);

    if (INVALID_HANDLE_VALUE == hFind)
    {
        _tprintf( TEXT("Directory file does not exist\n"));
        return 1;
    }    
    do {
        FileTimeToDosDateTime( &(wfd.ftLastWriteTime), &wFatDate, &wFatTime);

        _tprintf( 
            TEXT("%s/%02ld/%02ld %02ld:%02ld\t"),
            tszMonths[(wFatDate >> 5) & 0x000F],
            wFatDate & 0x001F,                    
            (wFatDate >> 9) & 0x007F,
            (wFatTime >> 11) & 0x001F,
            (wFatTime >> 5) & 0x003F);

        if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        {
            wprintf( TEXT("[%s]\n"),wfd.cFileName);
        }
        else
        {
            wprintf( TEXT("%s\n"),wfd.cFileName);
        }
    } while ( CeFindNextFile( hFind, &wfd));

    CeFindClose( hFind);

    _tprintf( TEXT("Closing connection ..."));
    CeRapiUninit();
    _tprintf( TEXT("Done\n"));
    
    return 0;
}

        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -