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

📄 listallfile.h

📁 huffman 压缩算法 支持文件夹的压缩与解压
💻 H
字号:

#ifndef LISTALLFILE_H
#define LISTALLFILE_H


LPTSTR namelist[1024];
int nCount=0;



int ListAllFile (LPTSTR dir)
{
    WIN32_FIND_DATA FindFileData;
    HANDLE hFind = INVALID_HANDLE_VALUE;

    DWORD dwError;
    LPTSTR DirSpec1;
    LPTSTR DirSpec2;
    size_t length_of_arg;
    INT retval;
    DirSpec1 = (LPTSTR) malloc (BUFSIZE);
    DirSpec2 = (LPTSTR) malloc (BUFSIZE);
    if ( DirSpec1 == NULL )
    {
        printf( "Insufficient memory available\n" );
        retval = 1;
        goto Cleanup;
    }


    // Check for the directory to query, specified as
    // a command-line parameter; otherwise, print usage.

    // Check that the input is not larger than allowed.
    StringCbLength(dir, BUFSIZE, &length_of_arg);

    if (length_of_arg > (BUFSIZE - 2))
    {
        _tprintf(TEXT("Input directory is too large.\n"));
        retval = 3;
        goto Cleanup;
    }

    //_tprintf (TEXT("Target directory is %s\n"), dir);

    // Prepare string for use with FindFile functions.  First,
    // copy the string to a buffer, then append '\*' to the
    // directory name.
    StringCbCopyN (DirSpec1, BUFSIZE, dir, length_of_arg+1);
    StringCbCatN (DirSpec1, BUFSIZE, TEXT("\\*"), 2*sizeof(TCHAR));

    // Find the first file in the directory.
    hFind = FindFirstFile(DirSpec1, &FindFileData);

    if (hFind == INVALID_HANDLE_VALUE)
    {
       // _tprintf (TEXT("Invalid file handle. Error is %u.\n"),GetLastError());
        retval = (-1);
        goto Cleanup;
    }
    else
    {
        // _tprintf (TEXT("First file name is: %s\n"), FindFileData.cFileName);
        //   _tprintf (TEXT("First file name is: %s\\%s\n"), dir,FindFileData.cFileName);
        // List all the other files in the directory.
        while (FindNextFile(hFind, &FindFileData) != 0)
        {
            if (FindFileData.dwFileAttributes==16&&wcscmp(FindFileData.cFileName, L"..")!=0)//是文件夹且不是..
            {
                //      _tprintf (TEXT("Next file name is: %s\\%s(DIR)\n"), dir,FindFileData.cFileName);
                StringCbCopyN (DirSpec2, BUFSIZE, dir, length_of_arg+1);
                StringCbCatN (DirSpec2, BUFSIZE, TEXT("\\"), 1*sizeof(TCHAR));
                StringCbCatN (DirSpec2, BUFSIZE, FindFileData.cFileName, wcslen(FindFileData.cFileName)*sizeof(TCHAR));
                ListAllFile (DirSpec2);
            }
            else
                //_tprintf (TEXT("Next file name is: %s %d\n"), FindFileData.cFileName,wcslen(FindFileData.cFileName));
                //  _tprintf (TEXT("Next file name is: %s \n"), FindFileData.cFileName);
               //	  _tprintf (TEXT("Next file name is: %s\\%s\n"), dir,FindFileData.cFileName);
                if (FindFileData.dwFileAttributes!=16)
                {
                    namelist[nCount]=(LPTSTR)malloc(BUFSIZE);
                    StringCbCopyN (namelist[nCount], BUFSIZE, dir, length_of_arg);
                    StringCbCatN (namelist[nCount], BUFSIZE, TEXT("\\"), 1*sizeof(TCHAR));
                    StringCbCatN (namelist[nCount], BUFSIZE, FindFileData.cFileName, wcslen(FindFileData.cFileName)*sizeof(TCHAR));
                    nCount++;
                }
        }
        dwError = GetLastError();
        FindClose(hFind);
        if (dwError != ERROR_NO_MORE_FILES)
        {
            _tprintf (TEXT("FindNextFile error. Error is %u.\n"),
                      dwError);
            retval = (-1);
            goto Cleanup;
        }
    }
    retval  = 0;

Cleanup:
    free(DirSpec1);
    free(DirSpec2);
    return retval;
}
#endif

⌨️ 快捷键说明

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