返回列表 发帖
以上几位修改的都不行呢 最后还是我那哥们儿搞定了 毕竟是他写的程序所以还是他自己比较熟悉 麻烦大家了 不好意思啊

TOP

本帖最后由 523066680 于 2015-11-22 23:45 编辑

最近重新学C,
没有测试链接的目录,
风格好渣……
#include <cstdio>
#include <cstdlib>
#include <cwchar>
#include <cstring>
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <locale.h>
#define NAME_MAX 1024
void func(wchar_t path[]);
static long long int TotalSize = 0;
static long long int FileCount = 0;
static long long int DirCount = 0;
int main(int argc, char *argv[] )
{
    setlocale( LC_ALL, ".936" );
    wchar_t wspath[1024] = L"";
    char ts_str[30] = "";
    if (argc > 1)
    {
        mbstowcs( wspath, argv[1], strlen(argv[1]) );
        _WDIR * a;
        DIR * b;
        if ( (a = _wopendir(wspath)) == NULL )
        {
            fprintf(stderr, "Argument is not correct!");
        }
        else
        {
            func( wspath );
            fprintf(stderr, "%20lld Folders\n", DirCount);
            fprintf(stderr, "%20lld Files\n"  , FileCount);
            fprintf(stderr, "%20lld Bytes\n"   , TotalSize);
            fprintf(stderr, "%20lld MB\n"      , TotalSize/1024/1024);
            fprintf(stderr, "%20lld GB"        , TotalSize/1024/1024/1024);
        }
    }
    else
    {
        fprintf(stderr, "No arguments!");
    }
   
    return 0;
}
void func(wchar_t path[])
{
    _WDIR * a = _wopendir(path);
    _wdirent * dp;
    _WDIR * aa;
    struct _stati64 stbuf;
    wchar_t fullpath[NAME_MAX] = L"";
    while (dp = _wreaddir(a))
    {
        if (
               wcscmp(dp->d_name, L".") == 0
            || wcscmp(dp->d_name, L"..") == 0  
        )
        {
            continue;
        }
        swprintf(fullpath, L"%ls\\%ls", path, dp->d_name);
        _wstati64(fullpath, &stbuf);
        if ( (stbuf.st_mode & S_IFMT) == S_IFDIR )
        {
            DirCount ++;
            func( fullpath );
        }
        else
        {
            TotalSize +=  (long long int)stbuf.st_size;
            FileCount ++;
        }
    }
    _wclosedir(a);
}COPY
                1962 Folders
               17329 Files
         76636660679 Bytes
               73086 MB
                  71 GB
1

评分人数

    • 依山居: 看你的骨骼精奇,是万中无一的武学奇才,维 ...技术 + 1
[url=][/url]

TOP

您能把修改好的程度共享出来看看吗?

TOP

回复 18# rogerzhao9


    8楼和11楼的代码有啥问题吗?
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

返回列表