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

📄 rapidir.cpp

📁 WinCE编程第三版收录的所有源代码(非常适合学习时
💻 CPP
字号:
//======================================================================
// RapiDir - Returns the contents of a directory on a Windows CE system.
//
// Written for the book Programming Windows CE
// Copyright (C) 2003 Douglas Boling
//======================================================================
#include <windows.h>                 // For all that Windows stuff
#include <stdio.h>
#include "rapi.h"                    // RAPI includes
// RapiDir.cpp : Defines the entry point for the console application.
//

//#include "stdafx.h"

//int _tmain(int argc, _TCHAR* argv[])
//{


//======================================================================
// main - Program entry point
//
int main (int argc, char **argv) {
    RAPIINIT ri;
    char szSrch[MAX_PATH], *pPtr;
    WCHAR szwDir[MAX_PATH];
    CE_FIND_DATA *pfd = 0;
    DWORD i, cItems, dwTotal = 0;
    FILETIME ft;
    SYSTEMTIME st;
    char ampm = 'a';
    INT rc;

    // Call RapiInitEx to asynchronously start RAPI session.
    ri.cbSize = sizeof (ri);
    rc = CeRapiInitEx (&ri);
    if (rc != NOERROR) {
        printf (TEXT ("Rapi Initialization failed\r\n"));
        return 0;
    }
    // Wait 5 seconds for connect.
    rc = WaitForSingleObject (ri.heRapiInit, 5000);
    if (rc == WAIT_OBJECT_0) {
        if (ri.hrRapiInit != NOERROR) {
            printf (TEXT ("Rapi Initialization failed.\r\n"));
            return 0;
        }
    } else if (rc == WAIT_TIMEOUT) {
        printf (TEXT ("Rapi Initialization timed out.\r\n"));
        return 0;
    }
    // If no argument, assume root directory.
    if (argc > 1)
        lstrcpy (szSrch, argv[1]);
    else
        lstrcpy (szSrch, "\\");

    // Point to end of name.
    pPtr = szSrch + lstrlen (szSrch) - 1;

    // Strip any trailing backslash.
    if (*pPtr == '\\')
        *pPtr = '\0';

    // Look for wildcards in filename. pPtr points to string end.
    for (i = 0; (pPtr >= szSrch) && (*pPtr != '\\'); pPtr--) {
        if ((*pPtr == '*') || (*pPtr == '?'))
            i++;
    }
    // Display dir name first so that on long calls we show we're alive.
    if (pPtr >= szSrch) {
        char ch;
        ch = *pPtr;
        *pPtr = '\0';
        printf (TEXT ("\r\n Directory of %s\r\n\r\n"), szSrch);
        *pPtr = ch;
    } else if (i)
        printf (TEXT ("\r\n Directory of \\\r\n\r\n"));
    else
        printf (TEXT ("\r\n Directory of %s\r\n\r\n"), szSrch);
    // No wildcards, append *.*
    if (i == 0)
        lstrcat (szSrch, "\\*.*");

    // Convert ANSI string to Unicode.
    mbstowcs (szwDir, szSrch, lstrlen (szSrch) + 1);
    // RAPI call
    rc = CeFindAllFiles (szwDir, FAF_SIZE_LOW | FAF_NAME |
                         FAF_ATTRIBUTES | FAF_LASTACCESS_TIME,
                         &cItems, &pfd);

    // Display the results.
    if (cItems) {
        for (i = 0; i < cItems; i++) {
            // Convert file time.
            FileTimeToLocalFileTime (&pfd->ftLastAccessTime, &ft);
            FileTimeToSystemTime (&ft, &st);
            // Adjust for AM/PM.
            if (st.wHour == 0)
                st.wHour = 12;
            else if (st.wHour > 11) {
                ampm = 'p';
                if (st.wHour > 12)
                    st.wHour -= 12;
            }
            printf (TEXT ("%02d/%02d/%02d  %02d:%02d%c\t"),
                    st.wMonth, st.wDay, st.wYear,
                    st.wHour, st.wMinute, ampm);

            // Display dir marker or file size.
            if (pfd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
                printf (TEXT ("<DIR>\t\t "));
            else {
                printf (TEXT ("\t%8d "), pfd->nFileSizeLow);
                dwTotal += pfd->nFileSizeLow;
            }
/*
#define FILE_ATTRIBUTE_READONLY             0x00000001  
#define FILE_ATTRIBUTE_HIDDEN               0x00000002  
#define FILE_ATTRIBUTE_SYSTEM               0x00000004  
#define FILE_ATTRIBUTE_DIRECTORY            0x00000010  
#define FILE_ATTRIBUTE_ARCHIVE              0x00000020  
#define FILE_ATTRIBUTE_INROM                0x00000040
#define FILE_ATTRIBUTE_ENCRYPTED            0x00000040  
#define FILE_ATTRIBUTE_NORMAL               0x00000080  
#define FILE_ATTRIBUTE_TEMPORARY            0x00000100  
#define FILE_ATTRIBUTE_SPARSE_FILE          0x00000200
#define MODULE_ATTR_NOT_TRUSTED             0x00000200  
#define FILE_ATTRIBUTE_REPARSE_POINT        0x00000400  
#define MODULE_ATTR_NODEBUG                 0x00000400
#define FILE_ATTRIBUTE_COMPRESSED           0x00000800  
#define FILE_ATTRIBUTE_OFFLINE              0x00001000  
#define FILE_ATTRIBUTE_ROMSTATICREF         0x00001000
#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED  0x00002000  
#define FILE_ATTRIBUTE_ROMMODULE            0x00002000
*/
			printf ("%c", (pfd->dwFileAttributes & 0x2000) ? 'X' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x1000) ? 'S' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x0800) ? 'C' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x0400) ? 'd' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x0200) ? 'n' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x0100) ? 'T' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x0080) ? 'N' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x0040) ? 'r' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x0020) ? 'A' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x0010) ? 'D' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x0008) ? '8' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x0004) ? 'S' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x0002) ? 'H' : '-');
			printf ("%c", (pfd->dwFileAttributes & 0x0001) ? 'R' : '-');
			printf ("  ");


            // Display name, use Cap %S to indicate Unicode.
            printf (TEXT ("%S\r\n"), pfd->cFileName);
            pfd++;
        }
        printf (TEXT ("\t%10d File(s)\t%9d bytes\r\n\r\n"),
                cItems, dwTotal);
    } else
        printf (TEXT ("File not Found\r\n\r\n"));
   // Clean up by freeing the FindAllFiles buffer.
   if (pfd)
       CeRapiFreeBuffer (pfd);
    // Clean up by uninitializing RAPI.
    CeRapiUninit ();
    return 0;
}


⌨️ 快捷键说明

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